From: David A. Velasco Date: Tue, 1 Sep 2015 16:35:51 +0000 (+0200) Subject: Merge branch 'master' into copy X-Git-Tag: oc-android-1.8~22^2~1 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/e6be60679fd7bc781dbd7a2a2b82d58eb720b746?ds=inline;hp=--cc Merge branch 'master' into copy Conflicts FIXED: src/com/owncloud/android/ui/activity/FileDisplayActivity.java src/com/owncloud/android/ui/fragment/OCFileListFragment.java src/com/owncloud/android/ui/preview/FileDownloadFragment.java src/com/owncloud/android/ui/preview/PreviewImageFragment.java src/com/owncloud/android/ui/preview/PreviewMediaFragment.java --- e6be60679fd7bc781dbd7a2a2b82d58eb720b746 diff --cc AndroidManifest.xml index fa3dd706,fc701a94..a072d788 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@@ -36,9 -37,10 +36,9 @@@ + android:targetSdkVersion="22" /> - - + 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. */ @@@ -151,13 -207,13 +207,13 @@@ super.onSaveInstanceState(outState); outState.putParcelable(KEY_FILE, mFile); } - + /** * Call this, when the user presses the up button. - *

- * ++ * * 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. - * + *

* return Count of folder levels browsed up. */ public int onBrowseUp() { @@@ -242,12 -298,11 +298,11 @@@ * {@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); @@@ -350,15 -403,22 +403,29 @@@ 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; } } diff --cc src/com/owncloud/android/ui/preview/FileDownloadFragment.java index 957d3384,dd78a039..e63b3245 --- a/src/com/owncloud/android/ui/preview/FileDownloadFragment.java +++ b/src/com/owncloud/android/ui/preview/FileDownloadFragment.java @@@ -140,13 -135,12 +136,12 @@@ public class FileDownloadFragment exten } } - 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() { @@@ -158,14 -152,13 +153,14 @@@ if (mError) { setButtonsForRemote(); - } else { + } + else { setButtonsForTransferring(); } - + - return view; + return mView; } - + @Override public void onSaveInstanceState(Bundle outState) { diff --cc src/com/owncloud/android/ui/preview/PreviewImageFragment.java index 6dd18658,6ce592a7..b6f36823 --- a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java @@@ -200,11 -201,12 +201,12 @@@ public class PreviewImageFragment exten 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"); @@@ -362,9 -358,9 +364,9 @@@ mContainerActivity.getFileOperationsHelper().openFile(getFile()); finish(); } - + - - private class LoadBitmapTask extends AsyncTask { + + private class LoadBitmapTask extends AsyncTask { /** * Weak reference to the target {@link ImageView} where the bitmap will be loaded into. @@@ -409,13 -405,13 +411,13 @@@ mMessageViewRef = new WeakReference(messageView); mProgressWheelRef = new WeakReference(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(...) @@@ -466,43 -462,48 +468,50 @@@ } 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(); diff --cc src/com/owncloud/android/ui/preview/PreviewMediaFragment.java index 02aebd0c,b197a855..0dbb1a32 --- a/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java @@@ -200,16 -203,39 +203,40 @@@ public class PreviewMediaFragment exten 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}