X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/3a8ff76d0a68d0ba18513c177b69bb8cb38e4189..00482b6dcb1e98da39df54374f7098b51d66bee5:/src/com/owncloud/android/ui/preview/ImageViewCustom.java diff --git a/src/com/owncloud/android/ui/preview/ImageViewCustom.java b/src/com/owncloud/android/ui/preview/ImageViewCustom.java index ad851404..69182d6e 100644 --- a/src/com/owncloud/android/ui/preview/ImageViewCustom.java +++ b/src/com/owncloud/android/ui/preview/ImageViewCustom.java @@ -12,10 +12,16 @@ import android.widget.ImageView; import com.owncloud.android.lib.common.utils.Log_OC; public class ImageViewCustom extends ImageView { - + + private static final String TAG = ImageViewCustom.class.getSimpleName(); + private static final boolean IS_ICS_OR_HIGHER = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH; - - private Bitmap mBitmap; + private static final boolean IS_VERSION_BUGGY_ON_RECYCLES = + Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR1 || + Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR2; + + private int mBitmapHeight; + private int mBitmapWidth; public ImageViewCustom(Context context) { @@ -34,9 +40,13 @@ public class ImageViewCustom extends ImageView { @Override protected void onDraw(Canvas canvas) { - if(IS_ICS_OR_HIGHER && checkIfMaximumBitmapExceed(canvas)) { - // Set layer type to software one for avoiding exceed - // and problems in visualization + if(IS_ICS_OR_HIGHER && checkIfMaximumBitmapExceed(canvas) || IS_VERSION_BUGGY_ON_RECYCLES ) { + // Software type is set with two targets: + // 1. prevent that bitmaps larger than maximum textures allowed are shown as black views in devices + // with LAYER_TYPE_HARDWARE enabled by default; + // 2. grant that bitmaps are correctly dellocated from memory in versions suffering the bug fixed in + // https://android.googlesource.com/platform/frameworks/base/+/034de6b1ec561797a2422314e6ef03e3cd3e08e0; + // setLayerType(View.LAYER_TYPE_SOFTWARE, null); } @@ -45,26 +55,29 @@ public class ImageViewCustom extends ImageView { /** * Checks if current bitmaps exceed the maximum OpenGL texture size limit - * @param bitmap - * @return boolean + * @param canvas Canvas where the view will be drawn into. + * @return boolean True means that the bitmap is too big for the canvas. */ @SuppressLint("NewApi") private boolean checkIfMaximumBitmapExceed(Canvas canvas) { - Log_OC.d("OC", "Canvas maximum: " + canvas.getMaximumBitmapWidth() + " - " + canvas.getMaximumBitmapHeight()); - if (mBitmap!= null && (mBitmap.getWidth() > canvas.getMaximumBitmapWidth() - || mBitmap.getHeight() > canvas.getMaximumBitmapHeight())) { + Log_OC.v(TAG, "Canvas maximum: " + canvas.getMaximumBitmapWidth() + " - " + canvas.getMaximumBitmapHeight()); + if (mBitmapWidth > canvas.getMaximumBitmapWidth() + || mBitmapHeight > canvas.getMaximumBitmapHeight()) { return true; } return false; } + @Override /** - * Set current bitmap - * @param bitmap + * Keeps the size of the bitmap cached in member variables for faster access in {@link #onDraw(Canvas)} , + * but without keeping another reference to the {@link Bitmap} */ - public void setBitmap (Bitmap bitmap) { - mBitmap = bitmap; + public void setImageBitmap (Bitmap bm) { + mBitmapWidth = bm.getWidth(); + mBitmapHeight = bm.getHeight(); + super.setImageBitmap(bm); } }