Remove unused imports and split long lines modified
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / preview / ImageViewCustom.java
1 package com.owncloud.android.ui.preview;
2
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;
11
12 import com.owncloud.android.lib.common.utils.Log_OC;
13
14 public class ImageViewCustom extends ImageView {
15
16 private static final boolean IS_ICS_OR_HIGHER = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
17
18 private Bitmap mBitmap;
19
20
21 public ImageViewCustom(Context context) {
22 super(context);
23 }
24
25 public ImageViewCustom(Context context, AttributeSet attrs) {
26 super(context, attrs);
27 }
28
29 public ImageViewCustom(Context context, AttributeSet attrs, int defStyle) {
30 super(context, attrs, defStyle);
31 }
32
33 @SuppressLint("NewApi")
34 @Override
35 protected void onDraw(Canvas canvas) {
36
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);
41 }
42
43 super.onDraw(canvas);
44 }
45
46 /**
47 * Checks if current bitmaps exceed the maximum OpenGL texture size limit
48 * @param bitmap
49 * @return boolean
50 */
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())) {
56 return true;
57 }
58
59 return false;
60 }
61
62 /**
63 * Set current bitmap
64 * @param bitmap
65 */
66 public void setBitmap (Bitmap bitmap) {
67 mBitmap = bitmap;
68 }
69
70 }