<uses-sdk
android:minSdkVersion="14"
- android:targetSdkVersion="19" />
+ android:targetSdkVersion="22" />
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" >
- </uses-permission>
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<application
android:name=".MainApp"
getFileOperationsHelper().moveFile(folderToMoveAt, targetFile);
}
+ /**
+ * Request the operation for copying the file/folder from one path to another
+ *
+ * @param data Intent received
+ * @param resultCode Result code received
+ */
+ private void requestCopyOperation(Intent data, int resultCode) {
+ OCFile folderToMoveAt = data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);
+ OCFile targetFile = data.getParcelableExtra(FolderPickerActivity.EXTRA_FILE);
+ getFileOperationsHelper().copyFile(folderToMoveAt, targetFile);
+ }
+
@Override
public void onBackPressed() {
- OCFileListFragment listOfFiles = getListOfFilesFragment();
- if (mDualPane || getSecondFragment() == null) {
- OCFile currentDir = getCurrentDir();
- if (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID) {
- finish();
- return;
+ if (!isDrawerOpen()){
+ OCFileListFragment listOfFiles = getListOfFilesFragment();
+ if (mDualPane || getSecondFragment() == null) {
+ OCFile currentDir = getCurrentDir();
+ if (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID) {
+ finish();
+ return;
+ }
+ if (listOfFiles != null) { // should never be null, indeed
+ listOfFiles.onBrowseUp();
+ }
}
if (listOfFiles != null) { // should never be null, indeed
- listOfFiles.onBrowseUp();
+ setFile(listOfFiles.getCurrentFile());
}
+ cleanSecondFragment();
+ } else {
+ super.onBackPressed();
}
- if (listOfFiles != null) { // should never be null, indeed
- setFile(listOfFiles.getCurrentFile());
- }
- cleanSecondFragment();
-
}
@Override
}
removeStickyBroadcast(intent);
Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
- setSupportProgressBarIndeterminateVisibility(mSyncInProgress
- /*|| mRefreshSharesInProgress*/);
+ mProgressBar.setIndeterminate(mSyncInProgress);
+ //mProgressBar.setVisibility((mSyncInProgress) ? View.VISIBLE : View.INVISIBLE);
+ //setSupportProgressBarIndeterminateVisibility(mSyncInProgress
+ /*|| mRefreshSharesInProgress*/ //);
setBackgroundText();
-
+
}
-
+
if (synchResult != null) {
if (synchResult.getCode().equals(
RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED)) {
import com.owncloud.android.ui.dialog.RenameFileDialogFragment;
import com.owncloud.android.ui.preview.PreviewImageFragment;
import com.owncloud.android.ui.preview.PreviewMediaFragment;
-import com.owncloud.android.utils.DialogMenuItem;
import com.owncloud.android.utils.FileStorageUtils;
+import java.io.File;
+import java.util.Vector;
+
/**
* A Fragment that lists all files and folders in a given path.
- *
+ *
* TODO refactor to get rid of direct dependency on FileDisplayActivity
*/
- public class OCFileListFragment extends ExtendedListFragment {
-
+ public class OCFileListFragment extends ExtendedListFragment implements FileActionsDialogFragment.FileActionsDialogFragmentListener {
+
private static final String TAG = OCFileListFragment.class.getSimpleName();
private static final String MY_PACKAGE = OCFileListFragment.class.getPackage() != null ?
mJustFolders,
getActivity(),
mContainerActivity
- );
+ );
setListAdapter(mAdapter);
- registerForContextMenu();
+ registerLongClickListener();
}
+ private void registerLongClickListener() {
+ getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
+ public boolean onItemLongClick(AdapterView<?> arg0, View v,
+ int index, long arg3) {
+ showFileAction(index);
+ return true;
+ }
+ });
+ }
+
+
+ private void showFileAction(int fileIndex) {
+ Bundle args = getArguments();
+ PopupMenu pm = new PopupMenu(getActivity(),null);
+ Menu menu = pm.getMenu();
+
+ boolean allowContextualActions =
+ (args == null) ? true : args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, true);
+
+ if (allowContextualActions) {
+ MenuInflater inflater = getActivity().getMenuInflater();
+
+ inflater.inflate(R.menu.file_actions_menu, menu);
+ OCFile targetFile = (OCFile) mAdapter.getItem(fileIndex);
+
+ if (mContainerActivity.getStorageManager() != null) {
+ FileMenuFilter mf = new FileMenuFilter(
+ targetFile,
+ mContainerActivity.getStorageManager().getAccount(),
+ mContainerActivity,
+ getActivity()
+ );
+ mf.filter(menu);
+ }
+
+ /// TODO break this direct dependency on FileDisplayActivity... if possible
+ MenuItem item = menu.findItem(R.id.action_open_file_with);
+ FileFragment frag = ((FileDisplayActivity)getActivity()).getSecondFragment();
+ if (frag != null && frag instanceof FileDetailFragment &&
+ frag.getFile().getFileId() == targetFile.getFileId()) {
+ item = menu.findItem(R.id.action_see_details);
+ if (item != null) {
+ item.setVisible(false);
+ item.setEnabled(false);
+ }
+ }
+
+ FileActionsDialogFragment dialog = FileActionsDialogFragment.newInstance(menu, fileIndex);
+ dialog.setTargetFragment(this, 0);
+ dialog.show(getFragmentManager(), FileActionsDialogFragment.FTAG_FILE_ACTIONS);
+ }
+ }
+
/**
* Saves the current listed folder.
*/
super.onSaveInstanceState(outState);
outState.putParcelable(KEY_FILE, mFile);
}
-
+
/**
* Call this, when the user presses the up button.
- * <p/>
- *
++ *
* Tries to move up the current folder one level. If the parent folder was removed from the
* database, it continues browsing up until finding an existing folders.
- *
+ * <p/>
* return Count of folder levels browsed up.
*/
public int onBrowseUp() {
* {@inheritDoc}
*/
@Override
- public void onCreateContextMenu (
+ public void onCreateContextMenu(
ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
- super.onCreateContextMenu(menu, v, menuInfo);
Bundle args = getArguments();
- boolean allowContextualActions =
- (args == null) ? true : args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, true);
+ boolean allowContextualActions =
+ (args == null) ? true : args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, true);
if (allowContextualActions) {
MenuInflater inflater = getActivity().getMenuInflater();
inflater.inflate(R.menu.file_actions_menu, menu);
mContainerActivity.getFileOperationsHelper().toggleFavorite(mTargetFile, false);
return true;
}
+ case R.id.action_copy:
+ Intent action = new Intent(getActivity(), FolderPickerActivity.class);
+
+ // Pass mTargetFile that contains info of selected file/folder
+ action.putExtra(FolderPickerActivity.EXTRA_FILE, mTargetFile);
+ getActivity().startActivityForResult(action, FileDisplayActivity.ACTION_COPY_FILES);
+ return true;
default:
- return super.onContextItemSelected(item);
+ return false;
+ }
+ }
+
+ /**
+ * {@inhericDoc}
+ */
+ @Override
+ public boolean onContextItemSelected (MenuItem item) {
+ AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
+ boolean matched = onFileActionChosen(item.getItemId(), ((AdapterContextMenuInfo) item.getMenuInfo()).position);
+ if(!matched) {
+ return super.onContextItemSelected(item);
+ } else {
+ return matched;
}
}
}
}
- View view = null;
- view = inflater.inflate(R.layout.file_download_fragment, container, false);
- mView = view;
-
- ProgressBar progressBar = (ProgressBar) mView.findViewById(R.id.progressBar);
+ mView = inflater.inflate(R.layout.file_download_fragment, container, false);
+
+ ProgressBar progressBar = (ProgressBar)mView.findViewById(R.id.progressBar);
+ DisplayUtils.colorPreLollipopHorizontalProgressBar(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;
+ return mView;
}
-
+
@Override
public void onSaveInstanceState(Bundle outState) {
if (getFile() != null) {
mLoadBitmapTask = new LoadBitmapTask(mImageView, mMessageView, mProgressWheel);
//mLoadBitmapTask.execute(new String[]{getFile().getStoragePath()});
- mLoadBitmapTask.execute(getFile().getStoragePath());
+ // mLoadBitmapTask.execute(getFile().getStoragePath());
+ mLoadBitmapTask.execute(getFile());
}
}
-
-
+
+
@Override
public void onStop() {
Log_OC.d(TAG, "onStop starts");
mContainerActivity.getFileOperationsHelper().openFile(getFile());
finish();
}
-
+
-
- private class LoadBitmapTask extends AsyncTask<String, Void, Bitmap> {
+
+ private class LoadBitmapTask extends AsyncTask<OCFile, Void, LoadImage> {
/**
* Weak reference to the target {@link ImageView} where the bitmap will be loaded into.
mMessageViewRef = new WeakReference<TextView>(messageView);
mProgressWheelRef = new WeakReference<ProgressBar>(progressWheel);
}
-
+
-
@Override
- protected Bitmap doInBackground(String... params) {
+ protected LoadImage doInBackground(OCFile... params) {
Bitmap result = null;
if (params.length != 1) return null;
- String storagePath = params[0];
+ OCFile ocFile = params[0];
+ String storagePath = ocFile.getStoragePath();
try {
int maxDownScale = 3; // could be a parameter passed to doInBackground(...)
} catch (Throwable t) {
mErrorMessageId = R.string.common_error_unknown;
Log_OC.e(TAG, "Unexpected error loading " + getFile().getStoragePath(), t);
-
+
}
- return result;
+
+ return new LoadImage(result, ocFile);
}
-
+
@Override
- protected void onCancelled(Bitmap result) {
- if (result != null) {
- result.recycle();
+ protected void onCancelled(LoadImage result) {
+ if (result.bitmap != null) {
+ result.bitmap.recycle();
}
}
@Override
- protected void onPostExecute(Bitmap result) {
+ protected void onPostExecute(LoadImage result) {
hideProgressWheel();
- if (result != null) {
+ if (result.bitmap != null) {
showLoadedImage(result);
- } else {
+ }
+ else {
showErrorMessage();
}
- if (result != null && mBitmap != result) {
+ if (result.bitmap != null && mBitmap != result.bitmap) {
// unused bitmap, release it! (just in case)
- result.recycle();
+ result.bitmap.recycle();
}
}
-
+
@SuppressLint("InlinedApi")
- private void showLoadedImage(Bitmap result) {
+ private void showLoadedImage(LoadImage result) {
final ImageViewCustom imageView = mImageViewRef.get();
+ Bitmap bitmap = result.bitmap;
if (imageView != null) {
- Log_OC.d(TAG, "Showing image with resolution " + result.getWidth() + "x" +
- result.getHeight());
- imageView.setImageBitmap(result);
+ Log_OC.d(TAG, "Showing image with resolution " + bitmap.getWidth() + "x" +
+ bitmap.getHeight());
+
+ if (result.ocFile.getMimetype().equalsIgnoreCase("image/png")){
+ Drawable backrepeat = getResources().getDrawable(R.drawable.backrepeat);
+ imageView.setBackground(backrepeat);
+ }
+
+ imageView.setImageBitmap(bitmap);
imageView.setVisibility(View.VISIBLE);
- mBitmap = result; // needs to be kept for recycling when not useful
+ mBitmap = bitmap; // needs to be kept for recycling when not useful
}
final TextView messageView = mMessageViewRef.get();
mVideoPreview.setVisibility(View.VISIBLE);
mImagePreview.setVisibility(View.GONE);
prepareVideo();
-
- } else {
+
+ }
+ else {
mVideoPreview.setVisibility(View.GONE);
mImagePreview.setVisibility(View.VISIBLE);
+ extractAndSetCoverArt(file);
}
}
-
+
}
+ /**
+ * tries to read the cover art from the audio file and sets it as cover art.
+ *
+ * @param file audio file with potential cover art
+ */
+ private void extractAndSetCoverArt(OCFile file) {
+ if (file.isAudio()) {
+ try {
+ MediaMetadataRetriever mmr = new MediaMetadataRetriever();
+ mmr.setDataSource(file.getStoragePath());
+ byte[] data = mmr.getEmbeddedPicture();
+ if (data != null) {
+ Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
+ mImagePreview.setImageBitmap(bitmap); //associated cover art in bitmap
+ } else {
+ mImagePreview.setImageResource(R.drawable.logo);
+ }
+ } catch (Throwable t) {
+ mImagePreview.setImageResource(R.drawable.logo);
+ }
+ }
+ }
+
/**
* {@inheritDoc}