X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/c376eef2e7930eb4afee99b7657e3cc3672f7393..363cad2addd1d00c55baaad021356481ace68058:/src/com/owncloud/android/ui/preview/PreviewImageFragment.java diff --git a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java index 67cac5f3..aeca583a 100644 --- a/src/com/owncloud/android/ui/preview/PreviewImageFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewImageFragment.java @@ -16,6 +16,12 @@ */ package com.owncloud.android.ui.preview; +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FilterInputStream; +import java.io.IOException; +import java.io.InputStream; import java.lang.ref.WeakReference; import android.accounts.Account; @@ -24,7 +30,6 @@ import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.AsyncTask; -import android.os.Build; import android.os.Bundle; import android.support.v4.app.FragmentStatePagerAdapter; import android.view.LayoutInflater; @@ -38,7 +43,6 @@ import android.widget.TextView; import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuItem; -import com.ortiz.touch.TouchImageView; import com.owncloud.android.R; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.FileMenuFilter; @@ -46,6 +50,8 @@ import com.owncloud.android.lib.common.utils.Log_OC; 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.TouchImageViewCustom; + /** @@ -59,17 +65,12 @@ import com.owncloud.android.ui.fragment.FileFragment; */ public class PreviewImageFragment extends FileFragment { - private static final boolean IS_HONEYCOMB_OR_HIGHER = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB; - public static final String EXTRA_FILE = "FILE"; public static final String EXTRA_ACCOUNT = "ACCOUNT"; - public static final int MAX_OPENGL_TEXTURE_WIDTH = 2048; - public static final int MAX_OPENGL_TEXTURE_HEIGHT = 2048; - private View mView; private Account mAccount; - private TouchImageView mImageView; + private TouchImageViewCustom mImageView; private TextView mMessageView; private ProgressBar mProgressWheel; @@ -128,7 +129,7 @@ public class PreviewImageFragment extends FileFragment { Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); mView = inflater.inflate(R.layout.preview_image_fragment, container, false); - mImageView = (TouchImageView) mView.findViewById(R.id.image); + mImageView = (TouchImageViewCustom) mView.findViewById(R.id.image); mImageView.setVisibility(View.GONE); mImageView.setOnClickListener(new OnClickListener() { @Override @@ -310,6 +311,7 @@ public class PreviewImageFragment extends FileFragment { public void onDestroy() { if (mBitmap != null) { mBitmap.recycle(); + System.gc(); } super.onDestroy(); } @@ -331,7 +333,7 @@ public class PreviewImageFragment extends FileFragment { * * Using a weak reference will avoid memory leaks if the target ImageView is retired from memory before the load finishes. */ - private final WeakReference mImageViewRef; + private final WeakReference mImageViewRef; /** * Weak reference to the target {@link TextView} where error messages will be written. @@ -360,8 +362,8 @@ public class PreviewImageFragment extends FileFragment { * * @param imageView Target {@link ImageView} where the bitmap will be loaded into. */ - public BitmapLoader(ImageView imageView, TextView messageView, ProgressBar progressWheel) { - mImageViewRef = new WeakReference(imageView); + public BitmapLoader(ImageViewCustom imageView, TextView messageView, ProgressBar progressWheel) { + mImageViewRef = new WeakReference(imageView); mMessageViewRef = new WeakReference(messageView); mProgressWheelRef = new WeakReference(progressWheel); } @@ -373,8 +375,15 @@ public class PreviewImageFragment extends FileFragment { if (params.length != 1) return result; String storagePath = params[0]; try { - //Decode file into a bitmap in real size for being able to make zoom on the image - result = BitmapFactory.decodeFile(storagePath); + + + File picture = new File(storagePath); + + if (picture != null) { + //Decode file into a bitmap in real size for being able to make zoom on the image + result = BitmapFactory.decodeStream(new FlushedInputStream + (new BufferedInputStream(new FileInputStream(picture)))); + } if (result == null) { mErrorMessageId = R.string.preview_image_error_unknown_format; @@ -410,13 +419,9 @@ public class PreviewImageFragment extends FileFragment { @SuppressLint("InlinedApi") private void showLoadedImage(Bitmap result) { if (mImageViewRef != null) { - final ImageView imageView = mImageViewRef.get(); + final ImageViewCustom imageView = mImageViewRef.get(); if (imageView != null) { - if(IS_HONEYCOMB_OR_HIGHER && checkIfMaximumBitmapExceed(result)) { - // Set layer type to software one for avoiding exceed - // and problems in visualization - imageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); - } + imageView.setBitmap(result); imageView.setImageBitmap(result); imageView.setVisibility(View.VISIBLE); mBitmap = result; @@ -477,20 +482,31 @@ public class PreviewImageFragment extends FileFragment { container.finish(); } - public TouchImageView getImageView() { + public TouchImageViewCustom getImageView() { return mImageView; } - /** - * Checks if current bitmaps exceed the maximum OpenGL texture size limit - * @param bitmap - * @return boolean - */ - private boolean checkIfMaximumBitmapExceed(Bitmap bitmap) { - if (bitmap.getWidth() > MAX_OPENGL_TEXTURE_WIDTH - || bitmap.getHeight() > MAX_OPENGL_TEXTURE_HEIGHT) { - return true; + static class FlushedInputStream extends FilterInputStream { + public FlushedInputStream(InputStream inputStream) { + super(inputStream); + } + + @Override + public long skip(long n) throws IOException { + long totalBytesSkipped = 0L; + while (totalBytesSkipped < n) { + long bytesSkipped = in.skip(n - totalBytesSkipped); + if (bytesSkipped == 0L) { + int byteValue = read(); + if (byteValue < 0) { + break; // we reached EOF + } else { + bytesSkipped = 1; // we read one byte + } + } + totalBytesSkipped += bytesSkipped; + } + return totalBytesSkipped; } - return false; } }