From: tobiasKaminsky Date: Sat, 31 Oct 2015 07:10:34 +0000 (+0100) Subject: Merge remote-tracking branch 'remotes/upstream/resizedImages' into beta X-Git-Tag: beta-20151122~69 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/e6eb26a13057cdb4b5c3c67a624ebb1267111f4b?hp=-c Merge remote-tracking branch 'remotes/upstream/resizedImages' into beta --- e6eb26a13057cdb4b5c3c67a624ebb1267111f4b diff --combined src/com/owncloud/android/ui/preview/PreviewImageFragment.java index c45f76cf,f05391ad..dc96b9f2 --- a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java @@@ -26,7 -26,6 +26,7 @@@ import android.annotation.SuppressLint import android.app.Activity; import android.graphics.Bitmap; import android.graphics.Point; +import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.Bundle; import android.support.v4.app.FragmentStatePagerAdapter; @@@ -71,6 -70,7 +71,7 @@@ public class PreviewImageFragment exten private static final String ARG_FILE = "FILE"; private static final String ARG_IGNORE_FIRST = "IGNORE_FIRST"; + private static final String ARG_SHOW_RESIZED_IMAGE = "SHOW_RESIZED_IMAGE"; private TouchImageViewCustom mImageView; private TextView mMessageView; @@@ -79,11 -79,11 +80,11 @@@ private Boolean mShowResizedImage = false; public Bitmap mBitmap = null; - + private static final String TAG = PreviewImageFragment.class.getSimpleName(); private boolean mIgnoreFirstSavedState; - + private LoadBitmapTask mLoadBitmapTask = null; @@@ -108,11 -108,12 +109,12 @@@ Bundle args = new Bundle(); args.putParcelable(ARG_FILE, imageFile); args.putBoolean(ARG_IGNORE_FIRST, ignoreFirstSavedState); + args.putBoolean(ARG_SHOW_RESIZED_IMAGE, showResizedImage); frag.setArguments(args); return frag; } - + /** * Creates an empty fragment for image previews. @@@ -126,8 -127,8 +128,8 @@@ public PreviewImageFragment() { mIgnoreFirstSavedState = false; } - - + + /** * {@inheritDoc} */ @@@ -140,16 -141,17 +142,17 @@@ // not right now mIgnoreFirstSavedState = args.getBoolean(ARG_IGNORE_FIRST); + mShowResizedImage = args.getBoolean(ARG_SHOW_RESIZED_IMAGE); 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); @@@ -186,7 -188,7 +189,7 @@@ throw new IllegalStateException("Instanced with a NULL OCFile"); } } - + /** * {@inheritDoc} @@@ -196,7 -198,7 +199,7 @@@ super.onSaveInstanceState(outState); outState.putParcelable(PreviewImageFragment.EXTRA_FILE, getFile()); } - + @Override public void onStart() { @@@ -215,8 -217,9 +218,9 @@@ mImageView.setVisibility(View.VISIBLE); mBitmap = thumbnail; } else { - // generate new Thumbnail - if (ThumbnailsCacheManager.cancelPotentialWork(getFile(), mImageView)) { + // generate new Thumbnail + if (ThumbnailsCacheManager.cancelPotentialWork(getFile(), mImageView) && + mContainerActivity.getStorageManager() != null) { final ThumbnailsCacheManager.ThumbnailGenerationTask task = new ThumbnailsCacheManager.ThumbnailGenerationTask( mImageView, mContainerActivity.getStorageManager(), @@@ -237,12 -240,12 +241,12 @@@ } } else { mLoadBitmapTask = new LoadBitmapTask(mImageView, mMessageView, mProgressWheel); - mLoadBitmapTask.execute(getFile().getStoragePath()); + mLoadBitmapTask.execute(getFile()); } } } - - + + @Override public void onStop() { Log_OC.d(TAG, "onStop starts"); @@@ -252,7 -255,7 +256,7 @@@ } super.onStop(); } - + /** * {@inheritDoc} */ @@@ -268,11 -271,11 +272,11 @@@ @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(), @@@ -281,7 -284,7 +285,7 @@@ ); mf.filter(menu); } - + // additional restriction for this fragment // TODO allow renaming in PreviewImageFragment MenuItem item = menu.findItem(R.id.action_rename_file); @@@ -289,7 -292,7 +293,7 @@@ 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); @@@ -304,17 -307,11 +308,17 @@@ 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} */ @@@ -355,22 -352,15 +359,22 @@@ mContainerActivity.getFileOperationsHelper().syncFile(getFile()); return true; } - + case R.id.action_favorite_file:{ + mContainerActivity.getFileOperationsHelper().toggleFavorite(getFile(), true); + return true; + } + case R.id.action_unfavorite_file:{ + mContainerActivity.getFileOperationsHelper().toggleFavorite(getFile(), false); + return true; + } default: return false; } } - + private void seeDetails() { - mContainerActivity.showDetails(getFile()); + mContainerActivity.showDetails(getFile()); } @@@ -397,7 -387,7 +401,7 @@@ super.onDestroy(); } - + /** * Opens the previewed image with an external application. */ @@@ -405,9 -395,9 +409,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. @@@ -425,7 -415,7 +429,7 @@@ */ private final WeakReference mMessageViewRef; - + /** * Weak reference to the target {@link ProgressBar} shown while the load is in progress. * @@@ -434,17 -424,17 +438,17 @@@ */ private final WeakReference 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) { @@@ -452,13 -442,13 +456,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(...) @@@ -471,7 -461,7 +475,7 @@@ result = BitmapUtils.decodeSampledBitmapFromFile(storagePath, minWidth, minHeight); - if (isCancelled()) return result; + if (isCancelled()) return new LoadImage(result, ocFile); if (result == null) { mErrorMessageId = R.string.preview_image_error_unknown_format; @@@ -503,61 -493,48 +507,61 @@@ } 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; + + return new LoadImage(result, ocFile); } - + @Override - protected void onCancelled(Bitmap result) { - if (result != null) { - result.recycle(); + protected void onCancelled(LoadImage result) { + if (result != null && 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); + } + + if (result.ocFile.getMimetype().equalsIgnoreCase("image/gif")){ + imageView.setGifImage(result.ocFile); + } else { + 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(); @@@ -565,7 -542,7 +569,7 @@@ messageView.setVisibility(View.GONE); } // else , silently finish, the fragment was destroyed } - + private void showErrorMessage() { final ImageView imageView = mImageViewRef.get(); if (imageView != null) { @@@ -579,14 -556,14 +583,14 @@@ 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); } } - + } /** @@@ -600,7 -577,7 +604,7 @@@ return (file != null && file.isImage()); } - + /** * Finishes the preview */ @@@ -608,20 -585,9 +612,20 @@@ Activity container = getActivity(); container.finish(); } - + public TouchImageViewCustom getImageView() { return mImageView; } + private class LoadImage { + private Bitmap bitmap; + private OCFile ocFile; + + public LoadImage(Bitmap bitmap, OCFile ocFile){ + this.bitmap = bitmap; + this.ocFile = ocFile; + } + + } + }