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 boolean IS_ICS_OR_HIGHER
= Build
.VERSION
.SDK_INT
>= Build
.VERSION_CODES
.ICE_CREAM_SANDWICH
;
18 private Bitmap mBitmap
;
21 public ImageViewCustom(Context context
) {
25 public ImageViewCustom(Context context
, AttributeSet attrs
) {
26 super(context
, attrs
);
29 public ImageViewCustom(Context context
, AttributeSet attrs
, int defStyle
) {
30 super(context
, attrs
, defStyle
);
33 @SuppressLint("NewApi")
35 protected void onDraw(Canvas canvas
) {
37 if(IS_ICS_OR_HIGHER
&& checkIfMaximumBitmapExceed(canvas
)) {
38 // Set layer type to software one for avoiding exceed
39 // and problems in visualization
40 setLayerType(View
.LAYER_TYPE_SOFTWARE
, null
);
47 * Checks if current bitmaps exceed the maximum OpenGL texture size limit
51 @SuppressLint("NewApi")
52 private boolean checkIfMaximumBitmapExceed(Canvas canvas
) {
53 Log_OC
.d("OC", "Canvas maximum: " + canvas
.getMaximumBitmapWidth() + " - " + canvas
.getMaximumBitmapHeight());
54 if (mBitmap
!= null
&& (mBitmap
.getWidth() > canvas
.getMaximumBitmapWidth()
55 || mBitmap
.getHeight() > canvas
.getMaximumBitmapHeight())) {
66 public void setBitmap (Bitmap bitmap
) {