NekoX/TMessagesProj/src/main/java/org/telegram/android/ImageReceiver.java

727 lines
27 KiB
Java
Raw Normal View History

/*
* This is the source code of Telegram for Android v. 1.3.x.
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
* Copyright Nikolai Kudashov, 2013.
*/
package org.telegram.android;
import android.graphics.Bitmap;
2014-10-21 22:35:16 +02:00
import android.graphics.BitmapShader;
import android.graphics.Canvas;
2014-10-21 22:35:16 +02:00
import android.graphics.Matrix;
import android.graphics.Paint;
2015-01-02 23:15:07 +01:00
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
2014-10-21 22:35:16 +02:00
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
2015-01-02 23:15:07 +01:00
import org.telegram.messenger.TLObject;
import org.telegram.messenger.TLRPC;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.Utilities;
2015-02-01 19:51:02 +01:00
public class ImageReceiver implements NotificationCenter.NotificationCenterDelegate {
public static interface ImageReceiverDelegate {
public void didSetImage(ImageReceiver imageReceiver, boolean set, boolean thumb);
}
private View parentView;
private Integer tag;
private Integer thumbTag;
private MessageObject parentMessageObject;
private boolean canceledLoading;
private TLObject currentImageLocation;
private String currentKey;
private String currentThumbKey;
private String currentHttpUrl;
private String currentFilter;
private String currentThumbFilter;
private TLRPC.FileLocation currentThumbLocation;
private int currentSize;
private boolean currentCacheOnly;
private BitmapDrawable currentImage;
private BitmapDrawable currentThumb;
private Drawable staticThumb;
private boolean needsQualityThumb;
private boolean shouldGenerateQualityThumb;
private int imageX, imageY, imageW, imageH;
private Rect drawRegion = new Rect();
private boolean isVisible = true;
2015-02-01 19:51:02 +01:00
private boolean isAspectFit;
private boolean forcePreview;
private int roundRadius;
private BitmapShader bitmapShader;
private Paint roundPaint;
private RectF roundRect;
private RectF bitmapRect;
private Matrix shaderMatrix;
2015-01-02 23:15:07 +01:00
private int alpha = 255;
private boolean isPressed;
private boolean disableRecycle;
private int orientation;
private boolean centerRotation;
2015-02-01 19:51:02 +01:00
private ImageReceiverDelegate delegate;
public ImageReceiver() {
}
public ImageReceiver(View view) {
parentView = view;
}
2015-02-01 19:51:02 +01:00
public void cancelLoadImage() {
ImageLoader.getInstance().cancelLoadingForImageReceiver(this, 0);
canceledLoading = true;
}
2015-02-01 19:51:02 +01:00
public void setImage(TLObject path, String filter, Drawable thumb, boolean cacheOnly) {
setImage(path, null, filter, thumb, null, null, 0, cacheOnly);
}
2015-02-01 19:51:02 +01:00
public void setImage(TLObject path, String filter, Drawable thumb, int size, boolean cacheOnly) {
setImage(path, null, filter, thumb, null, null, size, cacheOnly);
}
2015-02-01 19:51:02 +01:00
public void setImage(String httpUrl, String filter, Drawable thumb, int size) {
setImage(null, httpUrl, filter, thumb, null, null, size, true);
}
public void setImage(TLObject fileLocation, String filter, TLRPC.FileLocation thumbLocation, String thumbFilter, boolean cacheOnly) {
setImage(fileLocation, null, filter, null, thumbLocation, thumbFilter, 0, cacheOnly);
}
public void setImage(TLObject fileLocation, String filter, TLRPC.FileLocation thumbLocation, String thumbFilter, int size, boolean cacheOnly) {
setImage(fileLocation, null, filter, null, thumbLocation, thumbFilter, size, cacheOnly);
}
public void setImage(TLObject fileLocation, String httpUrl, String filter, Drawable thumb, TLRPC.FileLocation thumbLocation, String thumbFilter, int size, boolean cacheOnly) {
if ((fileLocation == null && httpUrl == null && thumbLocation == null)
|| (fileLocation != null && !(fileLocation instanceof TLRPC.TL_fileLocation)
&& !(fileLocation instanceof TLRPC.TL_fileEncryptedLocation)
&& !(fileLocation instanceof TLRPC.TL_document))) {
recycleBitmap(null, false);
recycleBitmap(null, true);
currentKey = null;
currentThumbKey = null;
currentThumbFilter = null;
currentImageLocation = null;
currentHttpUrl = null;
currentFilter = null;
currentCacheOnly = false;
staticThumb = thumb;
currentThumbLocation = null;
currentSize = 0;
currentImage = null;
2015-02-01 19:51:02 +01:00
bitmapShader = null;
ImageLoader.getInstance().cancelLoadingForImageReceiver(this, 0);
if (parentView != null) {
parentView.invalidate();
}
2015-02-01 19:51:02 +01:00
if (delegate != null) {
delegate.didSetImage(this, currentImage != null || currentThumb != null || staticThumb != null, currentImage == null);
}
return;
}
2015-02-01 19:51:02 +01:00
if (!(thumbLocation instanceof TLRPC.TL_fileLocation)) {
thumbLocation = null;
}
2015-01-02 23:15:07 +01:00
String key = null;
if (fileLocation != null) {
2015-01-02 23:15:07 +01:00
if (fileLocation instanceof TLRPC.FileLocation) {
TLRPC.FileLocation location = (TLRPC.FileLocation) fileLocation;
key = location.volume_id + "_" + location.local_id;
} else if (fileLocation instanceof TLRPC.Document) {
TLRPC.Document location = (TLRPC.Document) fileLocation;
key = location.dc_id + "_" + location.id;
}
2015-02-01 19:51:02 +01:00
} else if (httpUrl != null) {
key = Utilities.MD5(httpUrl);
}
2015-02-01 19:51:02 +01:00
if (key != null) {
if (filter != null) {
key += "@" + filter;
}
}
2015-02-01 19:51:02 +01:00
if (currentKey != null && key != null && currentKey.equals(key)) {
if (delegate != null) {
delegate.didSetImage(this, currentImage != null || currentThumb != null || staticThumb != null, currentImage == null);
2015-01-02 23:15:07 +01:00
}
2015-02-01 19:51:02 +01:00
if (!canceledLoading && !forcePreview) {
return;
}
}
2015-02-01 19:51:02 +01:00
String thumbKey = null;
if (thumbLocation != null) {
thumbKey = thumbLocation.volume_id + "_" + thumbLocation.local_id;
if (thumbFilter != null) {
thumbKey += "@" + thumbFilter;
}
}
2015-02-01 19:51:02 +01:00
recycleBitmap(key, false);
recycleBitmap(thumbKey, true);
currentThumbKey = thumbKey;
currentKey = key;
currentImageLocation = fileLocation;
currentHttpUrl = httpUrl;
currentFilter = filter;
currentThumbFilter = thumbFilter;
currentSize = size;
currentCacheOnly = cacheOnly;
currentThumbLocation = thumbLocation;
staticThumb = thumb;
bitmapShader = null;
if (delegate != null) {
delegate.didSetImage(this, currentImage != null || currentThumb != null || staticThumb != null, currentImage == null);
2014-10-21 22:35:16 +02:00
}
2015-02-01 19:51:02 +01:00
ImageLoader.getInstance().loadImageForImageReceiver(this);
2014-08-29 23:06:04 +02:00
if (parentView != null) {
2014-06-12 21:55:13 +02:00
parentView.invalidate();
}
}
2015-02-01 19:51:02 +01:00
public void setDelegate(ImageReceiverDelegate delegate) {
this.delegate = delegate;
}
2015-01-02 23:15:07 +01:00
public void setPressed(boolean value) {
isPressed = value;
}
public boolean getPressed() {
return isPressed;
}
public void setOrientation(int angle, boolean center) {
orientation = angle;
centerRotation = center;
}
public int getOrientation() {
return orientation;
}
public void setImageBitmap(Bitmap bitmap) {
2015-01-02 23:15:07 +01:00
setImageBitmap(bitmap != null ? new BitmapDrawable(null, bitmap) : null);
}
public void setDisableRecycle(boolean value) {
disableRecycle = value;
}
public void setImageBitmap(Drawable bitmap) {
2015-02-01 19:51:02 +01:00
ImageLoader.getInstance().cancelLoadingForImageReceiver(this, 0);
recycleBitmap(null, false);
recycleBitmap(null, true);
staticThumb = bitmap;
currentThumbLocation = null;
currentKey = null;
currentThumbKey = null;
currentImage = null;
2015-02-01 19:51:02 +01:00
currentThumbFilter = null;
currentImageLocation = null;
currentHttpUrl = null;
currentFilter = null;
currentSize = 0;
currentCacheOnly = false;
2014-10-21 22:35:16 +02:00
bitmapShader = null;
2015-02-01 19:51:02 +01:00
if (delegate != null) {
delegate.didSetImage(this, currentImage != null || currentThumb != null || staticThumb != null, currentImage == null);
}
if (parentView != null) {
parentView.invalidate();
}
}
public void clearImage() {
2015-02-01 19:51:02 +01:00
recycleBitmap(null, false);
recycleBitmap(null, true);
if (needsQualityThumb) {
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messageThumbGenerated);
ImageLoader.getInstance().cancelLoadingForImageReceiver(this, 0);
}
}
2014-10-21 22:35:16 +02:00
public boolean draw(Canvas canvas) {
try {
2015-02-01 19:51:02 +01:00
BitmapDrawable bitmapDrawable = null;
if (!forcePreview && currentImage != null) {
bitmapDrawable = currentImage;
} else if (staticThumb instanceof BitmapDrawable) {
bitmapDrawable = (BitmapDrawable) staticThumb;
} else if (currentThumb != null) {
bitmapDrawable = currentThumb;
}
if (bitmapDrawable != null) {
2015-02-01 19:51:02 +01:00
Paint paint = bitmapDrawable.getPaint();
2015-01-02 23:15:07 +01:00
boolean hasFilter = paint != null && paint.getColorFilter() != null;
if (hasFilter && !isPressed) {
bitmapDrawable.setColorFilter(null);
hasFilter = false;
} else if (!hasFilter && isPressed) {
bitmapDrawable.setColorFilter(new PorterDuffColorFilter(0xffdddddd, PorterDuff.Mode.MULTIPLY));
hasFilter = true;
}
2014-10-21 22:35:16 +02:00
if (bitmapShader != null) {
drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
2014-11-12 23:16:59 +01:00
if (isVisible) {
roundRect.set(drawRegion);
shaderMatrix.reset();
shaderMatrix.setRectToRect(bitmapRect, roundRect, Matrix.ScaleToFit.FILL);
bitmapShader.setLocalMatrix(shaderMatrix);
canvas.drawRoundRect(roundRect, roundRadius, roundRadius, roundPaint);
}
} else {
int bitmapW;
int bitmapH;
int originalW = bitmapDrawable.getIntrinsicWidth();
int originalH = bitmapDrawable.getIntrinsicHeight();
if (orientation == 90 || orientation == 270) {
bitmapW = bitmapDrawable.getIntrinsicHeight();
bitmapH = bitmapDrawable.getIntrinsicWidth();
} else {
bitmapW = bitmapDrawable.getIntrinsicWidth();
bitmapH = bitmapDrawable.getIntrinsicHeight();
}
2014-10-21 22:35:16 +02:00
float scaleW = bitmapW / (float) imageW;
float scaleH = bitmapH / (float) imageH;
2014-07-10 02:15:58 +02:00
2014-10-21 22:35:16 +02:00
if (isAspectFit) {
float scale = Math.max(scaleW, scaleH);
canvas.save();
bitmapW /= scale;
bitmapH /= scale;
drawRegion.set(imageX + (imageW - bitmapW) / 2, imageY + (imageH - bitmapH) / 2, imageX + (imageW + bitmapW) / 2, imageY + (imageH + bitmapH) / 2);
2014-07-10 02:15:58 +02:00
bitmapDrawable.setBounds(drawRegion);
2014-10-21 22:35:16 +02:00
try {
2015-01-02 23:15:07 +01:00
bitmapDrawable.setAlpha(alpha);
2014-10-21 22:35:16 +02:00
bitmapDrawable.draw(canvas);
} catch (Exception e) {
2015-02-01 19:51:02 +01:00
if (bitmapDrawable == currentImage && currentKey != null) {
ImageLoader.getInstance().removeImage(currentKey);
currentKey = null;
} else if (bitmapDrawable == currentThumb && currentThumbKey != null) {
ImageLoader.getInstance().removeImage(currentThumbKey);
currentThumbKey = null;
2014-10-01 21:55:24 +02:00
}
2015-02-01 19:51:02 +01:00
setImage(currentImageLocation, currentHttpUrl, currentFilter, currentThumb, currentThumbLocation, currentThumbFilter, currentSize, currentCacheOnly);
2014-10-21 22:35:16 +02:00
FileLog.e("tmessages", e);
2014-07-10 02:15:58 +02:00
}
canvas.restore();
} else {
2014-10-21 22:35:16 +02:00
if (Math.abs(scaleW - scaleH) > 0.00001f) {
canvas.save();
canvas.clipRect(imageX, imageY, imageX + imageW, imageY + imageH);
if (orientation != 0) {
if (centerRotation) {
canvas.rotate(orientation, imageW / 2, imageH / 2);
} else {
canvas.rotate(orientation, 0, 0);
}
}
2014-10-21 22:35:16 +02:00
if (bitmapW / scaleH > imageW) {
bitmapW /= scaleH;
originalW /= scaleH;
2014-10-21 22:35:16 +02:00
drawRegion.set(imageX - (bitmapW - imageW) / 2, imageY, imageX + (bitmapW + imageW) / 2, imageY + imageH);
} else {
bitmapH /= scaleW;
originalH /= scaleW;
2014-10-21 22:35:16 +02:00
drawRegion.set(imageX, imageY - (bitmapH - imageH) / 2, imageX + imageW, imageY + (bitmapH + imageH) / 2);
}
if (orientation == 90 || orientation == 270) {
int width = (drawRegion.right - drawRegion.left) / 2;
int height = (drawRegion.bottom - drawRegion.top) / 2;
int centerX = (drawRegion.right + drawRegion.left) / 2;
int centerY = (drawRegion.top + drawRegion.bottom) / 2;
bitmapDrawable.setBounds(centerX - height, centerY - width, centerX + height, centerY + width);
} else {
bitmapDrawable.setBounds(drawRegion);
}
2014-10-21 22:35:16 +02:00
if (isVisible) {
try {
2015-01-02 23:15:07 +01:00
bitmapDrawable.setAlpha(alpha);
2014-10-21 22:35:16 +02:00
bitmapDrawable.draw(canvas);
} catch (Exception e) {
2015-02-01 19:51:02 +01:00
if (bitmapDrawable == currentImage && currentKey != null) {
ImageLoader.getInstance().removeImage(currentKey);
currentKey = null;
} else if (bitmapDrawable == currentThumb && currentThumbKey != null) {
ImageLoader.getInstance().removeImage(currentThumbKey);
currentThumbKey = null;
2014-10-21 22:35:16 +02:00
}
2015-02-01 19:51:02 +01:00
setImage(currentImageLocation, currentHttpUrl, currentFilter, currentThumb, currentThumbLocation, currentThumbFilter, currentSize, currentCacheOnly);
2014-10-21 22:35:16 +02:00
FileLog.e("tmessages", e);
}
}
canvas.restore();
} else {
canvas.save();
if (orientation != 0) {
if (centerRotation) {
canvas.rotate(orientation, imageW / 2, imageH / 2);
} else {
canvas.rotate(orientation, 0, 0);
}
}
2014-10-21 22:35:16 +02:00
drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
if (orientation == 90 || orientation == 270) {
int width = (drawRegion.right - drawRegion.left) / 2;
int height = (drawRegion.bottom - drawRegion.top) / 2;
int centerX = (drawRegion.right + drawRegion.left) / 2;
int centerY = (drawRegion.top + drawRegion.bottom) / 2;
bitmapDrawable.setBounds(centerX - height, centerY - width, centerX + height, centerY + width);
} else {
bitmapDrawable.setBounds(drawRegion);
}
2014-10-21 22:35:16 +02:00
if (isVisible) {
try {
2015-01-02 23:15:07 +01:00
bitmapDrawable.setAlpha(alpha);
2014-10-21 22:35:16 +02:00
bitmapDrawable.draw(canvas);
} catch (Exception e) {
2015-02-01 19:51:02 +01:00
if (bitmapDrawable == currentImage && currentKey != null) {
ImageLoader.getInstance().removeImage(currentKey);
currentKey = null;
} else if (bitmapDrawable == currentThumb && currentThumbKey != null) {
ImageLoader.getInstance().removeImage(currentThumbKey);
currentThumbKey = null;
2014-10-21 22:35:16 +02:00
}
2015-02-01 19:51:02 +01:00
setImage(currentImageLocation, currentHttpUrl, currentFilter, currentThumb, currentThumbLocation, currentThumbFilter, currentSize, currentCacheOnly);
2014-10-21 22:35:16 +02:00
FileLog.e("tmessages", e);
2014-10-01 21:55:24 +02:00
}
}
canvas.restore();
2014-07-10 02:15:58 +02:00
}
}
}
2014-08-29 23:06:04 +02:00
return true;
2015-02-01 19:51:02 +01:00
} else if (staticThumb != null) {
2014-10-21 22:35:16 +02:00
drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
2015-02-01 19:51:02 +01:00
staticThumb.setBounds(drawRegion);
if (isVisible) {
2014-10-01 21:55:24 +02:00
try {
2015-02-01 19:51:02 +01:00
staticThumb.setAlpha(alpha);
staticThumb.draw(canvas);
2014-10-01 21:55:24 +02:00
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
2014-08-29 23:06:04 +02:00
return true;
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
2014-08-29 23:06:04 +02:00
return false;
}
public Bitmap getBitmap() {
2015-02-01 19:51:02 +01:00
if (currentImage != null) {
return currentImage.getBitmap();
} else if (currentThumb != null) {
return currentThumb.getBitmap();
} else if (staticThumb instanceof BitmapDrawable) {
return ((BitmapDrawable) staticThumb).getBitmap();
}
return null;
}
public int getBitmapWidth() {
Bitmap bitmap = getBitmap();
return orientation == 0 || orientation == 180 ? bitmap.getWidth() : bitmap.getHeight();
}
public int getBitmapHeight() {
Bitmap bitmap = getBitmap();
return orientation == 0 || orientation == 180 ? bitmap.getHeight() : bitmap.getWidth();
}
public void setVisible(boolean value, boolean invalidate) {
if (isVisible == value) {
return;
}
isVisible = value;
2014-06-12 21:55:13 +02:00
if (invalidate && parentView != null) {
parentView.invalidate();
}
}
public boolean getVisible() {
return isVisible;
}
2015-01-02 23:15:07 +01:00
public void setAlpha(float value) {
alpha = (int)(value * 255.0f);
}
public boolean hasImage() {
2015-02-01 19:51:02 +01:00
return currentImage != null || currentThumb != null || currentKey != null || currentHttpUrl != null || staticThumb != null;
}
public void setAspectFit(boolean value) {
isAspectFit = value;
}
public void setParentView(View view) {
parentView = view;
}
public void setImageCoords(int x, int y, int width, int height) {
imageX = x;
imageY = y;
imageW = width;
imageH = height;
}
public int getImageX() {
return imageX;
}
public int getImageY() {
return imageY;
}
public int getImageWidth() {
return imageW;
}
public int getImageHeight() {
return imageH;
}
public boolean isInsideImage(float x, float y) {
return x >= imageX && x <= imageX + imageW && y >= imageY && y <= imageY + imageH;
}
public Rect getDrawRegion() {
return drawRegion;
}
public String getFilter() {
2015-02-01 19:51:02 +01:00
return currentFilter;
}
public String getThumbFilter() {
return currentThumbFilter;
}
public String getKey() {
2015-02-01 19:51:02 +01:00
return currentKey;
}
public String getThumbKey() {
return currentThumbKey;
}
public int getSize() {
return currentSize;
}
public TLObject getImageLocation() {
return currentImageLocation;
}
public TLRPC.FileLocation getThumbLocation() {
return currentThumbLocation;
}
public String getHttpImageLocation() {
return currentHttpUrl;
}
public boolean getCacheOnly() {
return currentCacheOnly;
}
public void setForcePreview(boolean value) {
forcePreview = value;
}
2014-10-21 22:35:16 +02:00
2015-02-01 19:51:02 +01:00
public boolean isForcePreview() {
return forcePreview;
}
2014-10-21 22:35:16 +02:00
public void setRoundRadius(int value) {
roundRadius = value;
if (roundRadius != 0) {
2014-11-12 23:16:59 +01:00
if (roundPaint == null) {
roundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
roundRect = new RectF();
shaderMatrix = new Matrix();
bitmapRect = new RectF();
}
2014-10-21 22:35:16 +02:00
} else {
roundPaint = null;
roundRect = null;
shaderMatrix = null;
bitmapRect = null;
}
}
2014-11-17 03:44:57 +01:00
public int getRoundRadius() {
return roundRadius;
}
2015-02-01 19:51:02 +01:00
public void setParentMessageObject(MessageObject messageObject) {
parentMessageObject = messageObject;
}
public MessageObject getParentMessageObject() {
return parentMessageObject;
}
public void setNeedsQualityThumb(boolean value) {
needsQualityThumb = value;
if (needsQualityThumb) {
NotificationCenter.getInstance().addObserver(this, NotificationCenter.messageThumbGenerated);
} else {
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.messageThumbGenerated);
}
}
public boolean isNeedsQualityThumb() {
return needsQualityThumb;
}
public void setShouldGenerateQualityThumb(boolean value) {
shouldGenerateQualityThumb = value;
}
public boolean isShouldGenerateQualityThumb() {
return shouldGenerateQualityThumb;
}
protected Integer getTag(boolean thumb) {
if (thumb) {
return thumbTag;
} else {
return tag;
}
}
protected void setTag(Integer value, boolean thumb) {
if (thumb) {
thumbTag = value;
} else {
tag = value;
}
}
protected void setImageBitmapByKey(BitmapDrawable bitmap, String key, boolean thumb) {
if (bitmap == null || key == null) {
return;
}
if (!thumb) {
if (currentKey == null || !key.equals(currentKey)) {
return;
}
ImageLoader.getInstance().incrementUseCount(currentKey);
currentImage = bitmap;
if (roundRadius != 0 && bitmap instanceof BitmapDrawable) {
Bitmap object = bitmap.getBitmap();
bitmapShader = new BitmapShader(object, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
roundPaint.setShader(bitmapShader);
bitmapRect.set(0, 0, object.getWidth(), object.getHeight());
}
if (parentView != null) {
parentView.invalidate();
}
} else if (currentThumb == null && (currentImage == null || forcePreview)) {
if (currentThumbKey == null || !key.equals(currentThumbKey)) {
return;
}
ImageLoader.getInstance().incrementUseCount(currentThumbKey);
currentThumb = bitmap;
if (!(staticThumb instanceof BitmapDrawable) && parentView != null) {
parentView.invalidate();
}
}
if (delegate != null) {
delegate.didSetImage(this, currentImage != null || currentThumb != null || staticThumb != null, currentImage == null);
}
}
private void recycleBitmap(String newKey, boolean thumb) {
String key;
BitmapDrawable image;
if (thumb) {
if (currentThumb == null) {
return;
}
key = currentThumbKey;
image = currentThumb;
} else {
if (currentImage == null) {
return;
}
key = currentKey;
image = currentImage;
}
BitmapDrawable newBitmap = null;
if (newKey != null) {
newBitmap = ImageLoader.getInstance().getImageFromMemory(newKey);
}
if (key == null || image == null || image == newBitmap || disableRecycle) {
return;
}
Bitmap bitmap = image.getBitmap();
boolean canDelete = ImageLoader.getInstance().decrementUseCount(key);
if (!ImageLoader.getInstance().isInCache(key)) {
if (ImageLoader.getInstance().runtimeHack != null) {
ImageLoader.getInstance().runtimeHack.trackAlloc(bitmap.getRowBytes() * bitmap.getHeight());
}
if (canDelete) {
bitmap.recycle();
ImageLoader.getInstance().callGC();
}
}
if (thumb) {
currentThumb = null;
currentThumbKey = null;
} else {
currentImage = null;
currentKey = null;
}
}
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.messageThumbGenerated) {
String key = (String) args[1];
if (currentThumbKey != null && currentThumbKey.equals(key)) {
if (currentThumb == null) {
ImageLoader.getInstance().incrementUseCount(currentThumbKey);
}
currentThumb = (BitmapDrawable) args[0];
if (staticThumb instanceof BitmapDrawable) {
staticThumb = null;
}
if (parentView != null) {
parentView.invalidate();
}
}
}
}
}