f56557b6c743bd8a89000b78bbfe19cdd613449f
1 package com
.owncloud
.android
.ui
.preview
;
3 import android
.annotation
.SuppressLint
;
4 import android
.content
.Context
;
5 import android
.graphics
.Bitmap
;
6 import android
.graphics
.Canvas
;
7 import android
.os
.Build
;
8 import android
.util
.AttributeSet
;
9 import android
.view
.View
;
10 import android
.widget
.ImageView
;
12 import com
.owncloud
.android
.lib
.common
.utils
.Log_OC
;
14 public class ImageViewCustom
extends ImageView
{
16 private static final String TAG
= ImageViewCustom
.class.getSimpleName();
18 private static final boolean IS_ICS_OR_HIGHER
= Build
.VERSION
.SDK_INT
>= Build
.VERSION_CODES
.ICE_CREAM_SANDWICH
;
20 private int mBitmapHeight
;
21 private int mBitmapWidth
;
24 public ImageViewCustom(Context context
) {
28 public ImageViewCustom(Context context
, AttributeSet attrs
) {
29 super(context
, attrs
);
32 public ImageViewCustom(Context context
, AttributeSet attrs
, int defStyle
) {
33 super(context
, attrs
, defStyle
);
36 @SuppressLint("NewApi")
38 protected void onDraw(Canvas canvas
) {
40 if(IS_ICS_OR_HIGHER
&& checkIfMaximumBitmapExceed(canvas
)) {
41 // Set layer type to software one for avoiding exceed
42 // and problems in visualization
43 setLayerType(View
.LAYER_TYPE_SOFTWARE
, null
);
50 * Checks if current bitmaps exceed the maximum OpenGL texture size limit
51 * @param canvas Canvas where the view will be drawn into.
52 * @return boolean True means that the bitmap is too big for the canvas.
54 @SuppressLint("NewApi")
55 private boolean checkIfMaximumBitmapExceed(Canvas canvas
) {
56 Log_OC
.v(TAG
, "Canvas maximum: " + canvas
.getMaximumBitmapWidth() + " - " + canvas
.getMaximumBitmapHeight());
57 if (mBitmapWidth
> canvas
.getMaximumBitmapWidth()
58 || mBitmapHeight
> canvas
.getMaximumBitmapHeight()) {
67 * Keeps the size of the bitmap cached in member variables for faster access in {@link #onDraw(Canvas)} ,
68 * but without keeping another reference to the {@link Bitmap}
70 public void setImageBitmap (Bitmap bm
) {
71 mBitmapWidth
= bm
.getWidth();
72 mBitmapHeight
= bm
.getHeight();
73 super.setImageBitmap(bm
);