2014-02-04 19:36:55 +01:00
|
|
|
/*
|
|
|
|
* 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).
|
|
|
|
*
|
2019-01-23 18:03:33 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2018.
|
2014-02-04 19:36:55 +01:00
|
|
|
*/
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
package org.telegram.messenger;
|
2014-02-04 19:36:55 +01:00
|
|
|
|
|
|
|
import android.graphics.Bitmap;
|
2014-10-21 22:35:16 +02:00
|
|
|
import android.graphics.BitmapShader;
|
2014-02-04 19:36:55 +01:00
|
|
|
import android.graphics.Canvas;
|
2015-05-03 13:48:36 +02:00
|
|
|
import android.graphics.ColorFilter;
|
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;
|
2014-06-07 01:35:21 +02:00
|
|
|
import android.graphics.Rect;
|
2014-10-21 22:35:16 +02:00
|
|
|
import android.graphics.RectF;
|
|
|
|
import android.graphics.Shader;
|
2014-02-04 19:36:55 +01:00
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.view.View;
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.TLObject;
|
|
|
|
import org.telegram.tgnet.TLRPC;
|
2016-01-11 18:19:48 +01:00
|
|
|
import org.telegram.ui.Components.AnimatedFileDrawable;
|
2019-01-23 18:03:33 +01:00
|
|
|
import org.telegram.ui.Components.RecyclableDrawable;
|
2014-02-04 19:36:55 +01:00
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
public class ImageReceiver implements NotificationCenter.NotificationCenterDelegate {
|
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
public interface ImageReceiverDelegate {
|
|
|
|
void didSetImage(ImageReceiver imageReceiver, boolean set, boolean thumb);
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public static class BitmapHolder {
|
|
|
|
|
|
|
|
private String key;
|
2019-03-03 21:40:48 +01:00
|
|
|
private boolean recycleOnRelease;
|
2018-07-30 04:07:02 +02:00
|
|
|
public Bitmap bitmap;
|
|
|
|
|
|
|
|
public BitmapHolder(Bitmap b, String k) {
|
|
|
|
bitmap = b;
|
|
|
|
key = k;
|
|
|
|
if (key != null) {
|
|
|
|
ImageLoader.getInstance().incrementUseCount(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
public BitmapHolder(Bitmap b) {
|
|
|
|
bitmap = b;
|
|
|
|
recycleOnRelease = true;
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public int getWidth() {
|
|
|
|
return bitmap != null ? bitmap.getWidth() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getHeight() {
|
|
|
|
return bitmap != null ? bitmap.getHeight() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isRecycled() {
|
|
|
|
return bitmap == null || bitmap.isRecycled();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void release() {
|
|
|
|
if (key == null) {
|
2019-03-03 21:40:48 +01:00
|
|
|
if (recycleOnRelease && bitmap != null) {
|
|
|
|
bitmap.recycle();
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
bitmap = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
boolean canDelete = ImageLoader.getInstance().decrementUseCount(key);
|
|
|
|
if (!ImageLoader.getInstance().isInCache(key)) {
|
|
|
|
if (canDelete) {
|
|
|
|
bitmap.recycle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
key = null;
|
|
|
|
bitmap = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private class SetImageBackup {
|
2019-02-08 03:30:32 +01:00
|
|
|
public Object fileLocation;
|
2015-05-03 13:48:36 +02:00
|
|
|
public String filter;
|
|
|
|
public Drawable thumb;
|
2019-02-08 03:30:32 +01:00
|
|
|
public Object thumbLocation;
|
2015-05-03 13:48:36 +02:00
|
|
|
public String thumbFilter;
|
2019-03-03 21:40:48 +01:00
|
|
|
public Object mediaLocation;
|
|
|
|
public String mediaFilter;
|
2015-05-03 13:48:36 +02:00
|
|
|
public int size;
|
2017-07-23 14:56:38 +02:00
|
|
|
public int cacheType;
|
2019-01-23 18:03:33 +01:00
|
|
|
public Object parentObject;
|
2015-05-21 23:27:27 +02:00
|
|
|
public String ext;
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
public final static int TYPE_IMAGE = 0;
|
|
|
|
public final static int TYPE_THUMB = 1;
|
|
|
|
private final static int TYPE_CROSSFDADE = 2;
|
|
|
|
public final static int TYPE_MEDIA = 3;
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private int currentAccount;
|
2015-02-01 19:51:02 +01:00
|
|
|
private View parentView;
|
2019-03-03 21:40:48 +01:00
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
private int param;
|
2019-01-23 18:03:33 +01:00
|
|
|
private Object currentParentObject;
|
2015-02-01 19:51:02 +01:00
|
|
|
private boolean canceledLoading;
|
2016-04-22 15:49:00 +02:00
|
|
|
private static PorterDuffColorFilter selectedColorFilter = new PorterDuffColorFilter(0xffdddddd, PorterDuff.Mode.MULTIPLY);
|
2017-12-08 18:35:59 +01:00
|
|
|
private static PorterDuffColorFilter selectedGroupColorFilter = new PorterDuffColorFilter(0xffbbbbbb, PorterDuff.Mode.MULTIPLY);
|
|
|
|
private boolean forceLoding;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private SetImageBackup setImageBackup;
|
|
|
|
|
2019-02-08 03:30:32 +01:00
|
|
|
private Object currentImageLocation;
|
2019-03-03 21:40:48 +01:00
|
|
|
private String currentImageKey;
|
|
|
|
private String currentImageFilter;
|
|
|
|
private int imageTag;
|
|
|
|
private Drawable currentImageDrawable;
|
|
|
|
private BitmapShader imageShader;
|
|
|
|
private int imageOrientation;
|
|
|
|
|
|
|
|
private Object currentThumbLocation;
|
2015-02-01 19:51:02 +01:00
|
|
|
private String currentThumbKey;
|
|
|
|
private String currentThumbFilter;
|
2019-03-03 21:40:48 +01:00
|
|
|
private int thumbTag;
|
|
|
|
private Drawable currentThumbDrawable;
|
|
|
|
private BitmapShader thumbShader;
|
|
|
|
private int thumbOrientation;
|
|
|
|
|
|
|
|
private Object currentMediaLocation;
|
|
|
|
private String currentMediaKey;
|
|
|
|
private String currentMediaFilter;
|
|
|
|
private int mediaTag;
|
|
|
|
private Drawable currentMediaDrawable;
|
|
|
|
private BitmapShader mediaShader;
|
|
|
|
|
|
|
|
private Drawable staticThumbDrawable;
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
private String currentExt;
|
2019-03-03 21:40:48 +01:00
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
private int currentSize;
|
2017-07-23 14:56:38 +02:00
|
|
|
private int currentCacheType;
|
2016-01-11 18:19:48 +01:00
|
|
|
private boolean allowStartAnimation = true;
|
2017-07-08 18:32:04 +02:00
|
|
|
private boolean allowDecodeSingleFrame;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
private boolean crossfadeWithOldImage;
|
2019-01-23 18:03:33 +01:00
|
|
|
private boolean crossfadingWithThumb;
|
2017-12-08 18:35:59 +01:00
|
|
|
private Drawable crossfadeImage;
|
|
|
|
private String crossfadeKey;
|
|
|
|
private BitmapShader crossfadeShader;
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
private boolean needsQualityThumb;
|
|
|
|
private boolean shouldGenerateQualityThumb;
|
2019-03-03 21:40:48 +01:00
|
|
|
private TLRPC.Document qulityThumbDocument;
|
2019-01-23 18:03:33 +01:00
|
|
|
private boolean currentKeyQuality;
|
2015-05-21 23:27:27 +02:00
|
|
|
private boolean invalidateAll;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
|
|
|
private int imageX, imageY, imageW, imageH;
|
2014-08-22 16:24:33 +02:00
|
|
|
private Rect drawRegion = new Rect();
|
2014-06-07 01:35:21 +02:00
|
|
|
private boolean isVisible = true;
|
2015-02-01 19:51:02 +01:00
|
|
|
private boolean isAspectFit;
|
|
|
|
private boolean forcePreview;
|
2017-07-23 14:56:38 +02:00
|
|
|
private boolean forceCrossfade;
|
2015-02-01 19:51:02 +01:00
|
|
|
private int roundRadius;
|
2019-03-03 21:40:48 +01:00
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
private Paint roundPaint;
|
2016-04-22 15:49:00 +02:00
|
|
|
private RectF roundRect = new RectF();
|
|
|
|
private RectF bitmapRect = new RectF();
|
|
|
|
private Matrix shaderMatrix = new Matrix();
|
2015-05-03 13:48:36 +02:00
|
|
|
private float overrideAlpha = 1.0f;
|
2017-12-08 18:35:59 +01:00
|
|
|
private int isPressed;
|
2015-02-26 02:32:51 +01:00
|
|
|
private boolean centerRotation;
|
2015-02-01 19:51:02 +01:00
|
|
|
private ImageReceiverDelegate delegate;
|
2015-05-03 13:48:36 +02:00
|
|
|
private float currentAlpha;
|
|
|
|
private long lastUpdateAlphaTime;
|
|
|
|
private byte crossfadeAlpha = 1;
|
2017-07-23 14:56:38 +02:00
|
|
|
private boolean manualAlphaAnimator;
|
2015-05-03 13:48:36 +02:00
|
|
|
private boolean crossfadeWithThumb;
|
|
|
|
private ColorFilter colorFilter;
|
2014-08-22 16:24:33 +02:00
|
|
|
|
|
|
|
public ImageReceiver() {
|
2016-04-22 15:49:00 +02:00
|
|
|
this(null);
|
2014-08-22 16:24:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public ImageReceiver(View view) {
|
|
|
|
parentView = view;
|
2019-01-23 18:03:33 +01:00
|
|
|
roundPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
|
2018-07-30 04:07:02 +02:00
|
|
|
currentAccount = UserConfig.selectedAccount;
|
2014-08-22 16:24:33 +02:00
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
public void cancelLoadImage() {
|
2017-12-08 18:35:59 +01:00
|
|
|
forceLoding = false;
|
2019-03-03 21:40:48 +01:00
|
|
|
ImageLoader.getInstance().cancelLoadingForImageReceiver(this, true);
|
2015-02-01 19:51:02 +01:00
|
|
|
canceledLoading = true;
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public void setForceLoading(boolean value) {
|
|
|
|
forceLoding = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isForceLoding() {
|
|
|
|
return forceLoding;
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public void setImage(TLObject path, String filter, Drawable thumb, String ext, Object parentObject, int cacheType) {
|
2019-02-08 03:30:32 +01:00
|
|
|
setImage(path, filter, thumb, null, null, 0, ext, parentObject, cacheType);
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public void setImage(TLObject path, String filter, Drawable thumb, int size, String ext, Object parentObject, int cacheType) {
|
2019-02-08 03:30:32 +01:00
|
|
|
setImage(path, filter, thumb, null, null, size, ext, parentObject, cacheType);
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
public void setImage(String httpUrl, String filter, Drawable thumb, String ext, int size) {
|
2019-02-08 03:30:32 +01:00
|
|
|
setImage(httpUrl, filter, thumb, null, null, size, ext, null, 1);
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public void setImage(TLObject fileLocation, String filter, TLObject thumbLocation, String thumbFilter, String ext, Object parentObject, int cacheType) {
|
2019-02-08 03:30:32 +01:00
|
|
|
setImage(fileLocation, filter, null, thumbLocation, thumbFilter, 0, ext, parentObject, cacheType);
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
public void setImage(Object fileLocation, String filter, TLObject thumbLocation, String thumbFilter, int size, String ext, Object parentObject, int cacheType) {
|
2019-02-08 03:30:32 +01:00
|
|
|
setImage(fileLocation, filter, null, thumbLocation, thumbFilter, size, ext, parentObject, cacheType);
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
2019-02-08 03:30:32 +01:00
|
|
|
public void setImage(Object fileLocation, String filter, Drawable thumb, Object thumbLocation, String thumbFilter, int size, String ext, Object parentObject, int cacheType) {
|
2019-03-03 21:40:48 +01:00
|
|
|
setImage(null, null, fileLocation, filter, thumb, thumbLocation, thumbFilter, size, ext, parentObject, cacheType);
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getLocationKey(Object fileLocation, Object parentObject) {
|
|
|
|
if (fileLocation instanceof SecureDocument) {
|
|
|
|
SecureDocument document = (SecureDocument) fileLocation;
|
|
|
|
return document.secureFile.dc_id + "_" + document.secureFile.id;
|
|
|
|
} else if (fileLocation instanceof TLRPC.FileLocation) {
|
|
|
|
TLRPC.FileLocation location = (TLRPC.FileLocation) fileLocation;
|
|
|
|
return location.volume_id + "_" + location.local_id;
|
|
|
|
} else if (fileLocation instanceof TLRPC.TL_photoStrippedSize) {
|
|
|
|
TLRPC.TL_photoStrippedSize location = (TLRPC.TL_photoStrippedSize) fileLocation;
|
|
|
|
if (location.bytes.length > 0) {
|
|
|
|
return "stripped" + FileRefController.getKeyForParentObject(parentObject);
|
|
|
|
}
|
|
|
|
} else if (fileLocation instanceof TLRPC.TL_photoSize || fileLocation instanceof TLRPC.TL_photoCachedSize) {
|
|
|
|
TLRPC.PhotoSize photoSize = (TLRPC.PhotoSize) fileLocation;
|
|
|
|
return photoSize.location.volume_id + "_" + photoSize.location.local_id;
|
|
|
|
} else if (fileLocation instanceof WebFile) {
|
|
|
|
WebFile location = (WebFile) fileLocation;
|
|
|
|
return Utilities.MD5(location.url);
|
|
|
|
} else if (fileLocation instanceof TLRPC.Document) {
|
|
|
|
TLRPC.Document location = (TLRPC.Document) fileLocation;
|
|
|
|
if (location.dc_id != 0) {
|
|
|
|
return location.dc_id + "_" + location.id;
|
|
|
|
}
|
|
|
|
} else if (fileLocation instanceof String) {
|
|
|
|
return Utilities.MD5((String) fileLocation);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
return null;
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
private boolean isInvalidLocation(Object fileLocation) {
|
|
|
|
return fileLocation != null &&
|
|
|
|
!(fileLocation instanceof TLRPC.TL_fileLocation)
|
2015-02-01 19:51:02 +01:00
|
|
|
&& !(fileLocation instanceof TLRPC.TL_fileEncryptedLocation)
|
2016-03-06 02:49:31 +01:00
|
|
|
&& !(fileLocation instanceof TLRPC.TL_document)
|
2018-07-30 04:07:02 +02:00
|
|
|
&& !(fileLocation instanceof WebFile)
|
|
|
|
&& !(fileLocation instanceof TLRPC.TL_documentEncrypted)
|
2019-01-23 18:03:33 +01:00
|
|
|
&& !(fileLocation instanceof TLRPC.PhotoSize)
|
2019-02-08 03:30:32 +01:00
|
|
|
&& !(fileLocation instanceof SecureDocument)
|
2019-03-03 21:40:48 +01:00
|
|
|
&& !(fileLocation instanceof String);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setImage(Object mediaLocation, String mediaFilter, Object fileLocation, String imageFilter, Drawable thumb, Object thumbLocation, String thumbFilter, int size, String ext, Object parentObject, int cacheType) {
|
|
|
|
if (setImageBackup != null) {
|
|
|
|
setImageBackup.fileLocation = null;
|
|
|
|
setImageBackup.thumbLocation = null;
|
|
|
|
setImageBackup.mediaLocation = null;
|
|
|
|
setImageBackup.thumb = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((fileLocation == null && thumbLocation == null && mediaLocation == null) || isInvalidLocation(fileLocation) || isInvalidLocation(mediaLocation)) {
|
|
|
|
for (int a = 0; a < 4; a++) {
|
2017-12-08 18:35:59 +01:00
|
|
|
recycleBitmap(null, a);
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
currentImageLocation = null;
|
|
|
|
currentImageKey = null;
|
|
|
|
currentImageFilter = null;
|
|
|
|
currentMediaLocation = null;
|
|
|
|
currentMediaKey = null;
|
|
|
|
currentMediaFilter = null;
|
|
|
|
currentThumbLocation = null;
|
2015-02-01 19:51:02 +01:00
|
|
|
currentThumbKey = null;
|
|
|
|
currentThumbFilter = null;
|
2019-03-03 21:40:48 +01:00
|
|
|
|
|
|
|
currentMediaDrawable = null;
|
|
|
|
mediaShader = null;
|
|
|
|
currentImageDrawable = null;
|
|
|
|
imageShader = null;
|
|
|
|
thumbShader = null;
|
|
|
|
crossfadeShader = null;
|
|
|
|
|
|
|
|
currentExt = ext;
|
2019-01-23 18:03:33 +01:00
|
|
|
currentParentObject = null;
|
2017-07-23 14:56:38 +02:00
|
|
|
currentCacheType = 0;
|
2019-03-03 21:40:48 +01:00
|
|
|
staticThumbDrawable = thumb;
|
|
|
|
currentAlpha = 1.0f;
|
2015-02-01 19:51:02 +01:00
|
|
|
currentSize = 0;
|
2019-03-03 21:40:48 +01:00
|
|
|
|
|
|
|
ImageLoader.getInstance().cancelLoadingForImageReceiver(this, true);
|
2014-07-03 00:39:05 +02:00
|
|
|
if (parentView != null) {
|
2015-05-21 23:27:27 +02:00
|
|
|
if (invalidateAll) {
|
|
|
|
parentView.invalidate();
|
|
|
|
} else {
|
|
|
|
parentView.invalidate(imageX, imageY, imageX + imageW, imageY + imageH);
|
|
|
|
}
|
2014-07-03 00:39:05 +02:00
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
if (delegate != null) {
|
2019-03-03 21:40:48 +01:00
|
|
|
delegate.didSetImage(this, currentImageDrawable != null || currentThumbDrawable != null || staticThumbDrawable != null || currentMediaDrawable != null, currentImageDrawable == null && currentMediaDrawable == null);
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
if (isInvalidLocation(thumbLocation)) {
|
2015-02-01 19:51:02 +01:00
|
|
|
thumbLocation = null;
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
String imageKey = getLocationKey(fileLocation, parentObject);
|
|
|
|
if (imageKey == null && fileLocation != null) {
|
|
|
|
fileLocation = null;
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
currentKeyQuality = false;
|
2019-03-03 21:40:48 +01:00
|
|
|
if (imageKey == null && needsQualityThumb && (parentObject instanceof MessageObject || qulityThumbDocument != null)) {
|
|
|
|
TLRPC.Document document = qulityThumbDocument != null ? qulityThumbDocument : ((MessageObject) parentObject).getDocument();
|
2019-01-23 18:03:33 +01:00
|
|
|
if (document != null && document.dc_id != 0 && document.id != 0) {
|
2019-03-03 21:40:48 +01:00
|
|
|
imageKey = "q_" + document.dc_id + "_" + document.id;
|
2019-01-23 18:03:33 +01:00
|
|
|
currentKeyQuality = true;
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
if (imageKey != null && imageFilter != null) {
|
|
|
|
imageKey += "@" + imageFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
String mediaKey = getLocationKey(mediaLocation, parentObject);
|
|
|
|
if (mediaKey == null && mediaLocation != null) {
|
|
|
|
mediaLocation = null;
|
|
|
|
}
|
|
|
|
if (mediaKey != null && mediaFilter != null) {
|
|
|
|
mediaKey += "@" + mediaFilter;
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
if (mediaKey == null && currentImageKey != null && currentImageKey.equals(imageKey) || currentMediaKey != null && currentMediaKey.equals(mediaKey)) {
|
2015-02-01 19:51:02 +01:00
|
|
|
if (delegate != null) {
|
2019-03-03 21:40:48 +01:00
|
|
|
delegate.didSetImage(this, currentImageDrawable != null || currentThumbDrawable != null || staticThumbDrawable != null || currentMediaDrawable != null, currentImageDrawable == null && currentMediaDrawable == null);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
if (!canceledLoading && !forcePreview) {
|
|
|
|
return;
|
2014-10-18 01:06:51 +02:00
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
String thumbKey = getLocationKey(thumbLocation, parentObject);
|
2019-01-23 18:03:33 +01:00
|
|
|
if (thumbKey != null && thumbFilter != null) {
|
|
|
|
thumbKey += "@" + thumbFilter;
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
if (crossfadeWithOldImage) {
|
2019-03-03 21:40:48 +01:00
|
|
|
if (currentImageDrawable != null) {
|
|
|
|
recycleBitmap(thumbKey, TYPE_THUMB);
|
|
|
|
recycleBitmap(null, TYPE_CROSSFDADE);
|
|
|
|
recycleBitmap(mediaKey, TYPE_MEDIA);
|
|
|
|
crossfadeShader = imageShader;
|
|
|
|
crossfadeImage = currentImageDrawable;
|
|
|
|
crossfadeKey = currentImageKey;
|
2019-01-23 18:03:33 +01:00
|
|
|
crossfadingWithThumb = false;
|
2019-03-03 21:40:48 +01:00
|
|
|
currentImageDrawable = null;
|
|
|
|
currentImageKey = null;
|
|
|
|
} else if (currentThumbDrawable != null) {
|
|
|
|
recycleBitmap(imageKey, TYPE_IMAGE);
|
|
|
|
recycleBitmap(null, TYPE_CROSSFDADE);
|
|
|
|
recycleBitmap(mediaKey, TYPE_MEDIA);
|
|
|
|
crossfadeShader = thumbShader;
|
|
|
|
crossfadeImage = currentThumbDrawable;
|
2017-12-08 18:35:59 +01:00
|
|
|
crossfadeKey = currentThumbKey;
|
2019-01-23 18:03:33 +01:00
|
|
|
crossfadingWithThumb = false;
|
2019-03-03 21:40:48 +01:00
|
|
|
currentThumbDrawable = null;
|
2019-01-23 18:03:33 +01:00
|
|
|
currentThumbKey = null;
|
2019-03-03 21:40:48 +01:00
|
|
|
} else if (staticThumbDrawable != null) {
|
|
|
|
recycleBitmap(imageKey, TYPE_IMAGE);
|
|
|
|
recycleBitmap(thumbKey, TYPE_THUMB);
|
|
|
|
recycleBitmap(null, TYPE_CROSSFDADE);
|
|
|
|
recycleBitmap(mediaKey, TYPE_MEDIA);
|
|
|
|
crossfadeShader = thumbShader;
|
|
|
|
crossfadeImage = staticThumbDrawable;
|
2019-01-23 18:03:33 +01:00
|
|
|
crossfadingWithThumb = false;
|
|
|
|
crossfadeKey = null;
|
2019-03-03 21:40:48 +01:00
|
|
|
currentThumbDrawable = null;
|
2017-12-08 18:35:59 +01:00
|
|
|
currentThumbKey = null;
|
|
|
|
} else {
|
2019-03-03 21:40:48 +01:00
|
|
|
recycleBitmap(imageKey, TYPE_IMAGE);
|
|
|
|
recycleBitmap(thumbKey, TYPE_THUMB);
|
|
|
|
recycleBitmap(null, TYPE_CROSSFDADE);
|
|
|
|
recycleBitmap(mediaKey, TYPE_MEDIA);
|
2017-12-08 18:35:59 +01:00
|
|
|
crossfadeShader = null;
|
|
|
|
}
|
|
|
|
} else {
|
2019-03-03 21:40:48 +01:00
|
|
|
recycleBitmap(imageKey, TYPE_IMAGE);
|
|
|
|
recycleBitmap(thumbKey, TYPE_THUMB);
|
|
|
|
recycleBitmap(null, TYPE_CROSSFDADE);
|
|
|
|
recycleBitmap(mediaKey, TYPE_MEDIA);
|
2017-12-08 18:35:59 +01:00
|
|
|
crossfadeShader = null;
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
|
|
|
currentImageLocation = fileLocation;
|
2019-03-03 21:40:48 +01:00
|
|
|
currentImageKey = imageKey;
|
|
|
|
currentImageFilter = imageFilter;
|
|
|
|
currentMediaLocation = mediaLocation;
|
|
|
|
currentMediaKey = mediaKey;
|
|
|
|
currentMediaFilter = mediaFilter;
|
|
|
|
currentThumbLocation = thumbLocation;
|
|
|
|
currentThumbKey = thumbKey;
|
2015-02-01 19:51:02 +01:00
|
|
|
currentThumbFilter = thumbFilter;
|
2019-03-03 21:40:48 +01:00
|
|
|
|
|
|
|
currentParentObject = parentObject;
|
|
|
|
currentExt = ext;
|
2015-02-01 19:51:02 +01:00
|
|
|
currentSize = size;
|
2017-07-23 14:56:38 +02:00
|
|
|
currentCacheType = cacheType;
|
2019-03-03 21:40:48 +01:00
|
|
|
staticThumbDrawable = thumb;
|
|
|
|
imageShader = null;
|
|
|
|
thumbShader = null;
|
|
|
|
mediaShader = null;
|
2015-05-03 13:48:36 +02:00
|
|
|
currentAlpha = 1.0f;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
|
|
|
if (delegate != null) {
|
2019-03-03 21:40:48 +01:00
|
|
|
delegate.didSetImage(this, currentImageDrawable != null || currentThumbDrawable != null || staticThumbDrawable != null || currentMediaDrawable != null, currentImageDrawable == null && currentMediaDrawable == 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) {
|
2015-05-21 23:27:27 +02:00
|
|
|
if (invalidateAll) {
|
|
|
|
parentView.invalidate();
|
|
|
|
} else {
|
|
|
|
parentView.invalidate(imageX, imageY, imageX + imageW, imageY + imageH);
|
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public boolean canInvertBitmap() {
|
2019-03-03 21:40:48 +01:00
|
|
|
return currentMediaDrawable instanceof ExtendedBitmapDrawable || currentImageDrawable instanceof ExtendedBitmapDrawable || currentThumbDrawable instanceof ExtendedBitmapDrawable || staticThumbDrawable instanceof ExtendedBitmapDrawable;
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
public void setColorFilter(ColorFilter filter) {
|
|
|
|
colorFilter = filter;
|
|
|
|
}
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
public void setDelegate(ImageReceiverDelegate delegate) {
|
|
|
|
this.delegate = delegate;
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public void setPressed(int value) {
|
2015-01-02 23:15:07 +01:00
|
|
|
isPressed = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getPressed() {
|
2017-12-08 18:35:59 +01:00
|
|
|
return isPressed != 0;
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
public void setOrientation(int angle, boolean center) {
|
2016-03-06 02:49:31 +01:00
|
|
|
while (angle < 0) {
|
|
|
|
angle += 360;
|
|
|
|
}
|
|
|
|
while (angle > 360) {
|
|
|
|
angle -= 360;
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
imageOrientation = thumbOrientation = angle;
|
2015-02-26 02:32:51 +01:00
|
|
|
centerRotation = center;
|
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
public void setInvalidateAll(boolean value) {
|
|
|
|
invalidateAll = value;
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public Drawable getStaticThumb() {
|
2019-03-03 21:40:48 +01:00
|
|
|
return staticThumbDrawable;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public int getAnimatedOrientation() {
|
2019-03-03 21:40:48 +01:00
|
|
|
AnimatedFileDrawable animation = getAnimation();
|
|
|
|
return animation != null ? animation.getOrientation() : 0;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
public int getOrientation() {
|
2019-03-03 21:40:48 +01:00
|
|
|
return imageOrientation;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
|
2014-03-31 16:14:49 +02:00
|
|
|
public void setImageBitmap(Bitmap bitmap) {
|
2015-01-02 23:15:07 +01:00
|
|
|
setImageBitmap(bitmap != null ? new BitmapDrawable(null, bitmap) : null);
|
|
|
|
}
|
|
|
|
|
2014-03-31 16:14:49 +02:00
|
|
|
public void setImageBitmap(Drawable bitmap) {
|
2019-03-03 21:40:48 +01:00
|
|
|
ImageLoader.getInstance().cancelLoadingForImageReceiver(this, true);
|
2019-01-23 18:03:33 +01:00
|
|
|
|
|
|
|
if (crossfadeWithOldImage) {
|
2019-03-03 21:40:48 +01:00
|
|
|
if (currentImageDrawable != null) {
|
|
|
|
recycleBitmap(null, TYPE_THUMB);
|
|
|
|
recycleBitmap(null, TYPE_CROSSFDADE);
|
|
|
|
recycleBitmap(null, TYPE_MEDIA);
|
|
|
|
crossfadeShader = imageShader;
|
|
|
|
crossfadeImage = currentImageDrawable;
|
|
|
|
crossfadeKey = currentImageKey;
|
2019-01-23 18:03:33 +01:00
|
|
|
crossfadingWithThumb = true;
|
2019-03-03 21:40:48 +01:00
|
|
|
} else if (currentThumbDrawable != null) {
|
|
|
|
recycleBitmap(null, TYPE_IMAGE);
|
|
|
|
recycleBitmap(null, TYPE_CROSSFDADE);
|
|
|
|
recycleBitmap(null, TYPE_MEDIA);
|
|
|
|
crossfadeShader = thumbShader;
|
|
|
|
crossfadeImage = currentThumbDrawable;
|
2019-01-23 18:03:33 +01:00
|
|
|
crossfadeKey = currentThumbKey;
|
|
|
|
crossfadingWithThumb = true;
|
2019-03-03 21:40:48 +01:00
|
|
|
} else if (staticThumbDrawable != null) {
|
|
|
|
recycleBitmap(null, TYPE_IMAGE);
|
|
|
|
recycleBitmap(null, TYPE_THUMB);
|
|
|
|
recycleBitmap(null, TYPE_CROSSFDADE);
|
|
|
|
recycleBitmap(null, TYPE_MEDIA);
|
|
|
|
crossfadeShader = thumbShader;
|
|
|
|
crossfadeImage = staticThumbDrawable;
|
2019-01-23 18:03:33 +01:00
|
|
|
crossfadingWithThumb = true;
|
|
|
|
crossfadeKey = null;
|
|
|
|
} else {
|
2019-03-03 21:40:48 +01:00
|
|
|
for (int a = 0; a < 4; a++) {
|
2019-01-23 18:03:33 +01:00
|
|
|
recycleBitmap(null, a);
|
|
|
|
}
|
|
|
|
crossfadeShader = null;
|
|
|
|
}
|
|
|
|
} else {
|
2019-03-03 21:40:48 +01:00
|
|
|
for (int a = 0; a < 4; a++) {
|
2019-01-23 18:03:33 +01:00
|
|
|
recycleBitmap(null, a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
if (staticThumbDrawable instanceof RecyclableDrawable) {
|
|
|
|
RecyclableDrawable drawable = (RecyclableDrawable) staticThumbDrawable;
|
2019-01-23 18:03:33 +01:00
|
|
|
drawable.recycle();
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
if (bitmap instanceof AnimatedFileDrawable) {
|
|
|
|
AnimatedFileDrawable fileDrawable = (AnimatedFileDrawable) bitmap;
|
|
|
|
fileDrawable.setParentView(parentView);
|
|
|
|
if (allowStartAnimation) {
|
|
|
|
fileDrawable.start();
|
|
|
|
}
|
|
|
|
fileDrawable.setAllowDecodeSingleFrame(allowDecodeSingleFrame);
|
|
|
|
}
|
|
|
|
staticThumbDrawable = bitmap;
|
2017-12-08 18:35:59 +01:00
|
|
|
if (roundRadius != 0 && bitmap instanceof BitmapDrawable) {
|
2019-03-03 21:40:48 +01:00
|
|
|
if (bitmap instanceof AnimatedFileDrawable) {
|
|
|
|
((AnimatedFileDrawable) bitmap).setRoundRadius(roundRadius);
|
|
|
|
} else {
|
|
|
|
Bitmap object = ((BitmapDrawable) bitmap).getBitmap();
|
|
|
|
thumbShader = new BitmapShader(object, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
} else {
|
2019-03-03 21:40:48 +01:00
|
|
|
thumbShader = null;
|
2017-12-08 18:35:59 +01:00
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
currentMediaLocation = null;
|
|
|
|
currentMediaDrawable = null;
|
|
|
|
currentMediaKey = null;
|
|
|
|
currentMediaFilter = null;
|
|
|
|
mediaShader = null;
|
|
|
|
|
|
|
|
currentImageLocation = null;
|
|
|
|
currentImageDrawable = null;
|
|
|
|
currentImageKey = null;
|
|
|
|
currentImageFilter = null;
|
|
|
|
imageShader = null;
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
currentThumbLocation = null;
|
|
|
|
currentThumbKey = null;
|
|
|
|
currentThumbFilter = null;
|
2019-03-03 21:40:48 +01:00
|
|
|
|
|
|
|
currentKeyQuality = false;
|
|
|
|
currentExt = null;
|
2015-02-01 19:51:02 +01:00
|
|
|
currentSize = 0;
|
2017-07-23 14:56:38 +02:00
|
|
|
currentCacheType = 0;
|
2019-03-03 21:40:48 +01:00
|
|
|
currentAlpha = 1;
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
if (setImageBackup != null) {
|
|
|
|
setImageBackup.fileLocation = null;
|
|
|
|
setImageBackup.thumbLocation = null;
|
2019-03-03 21:40:48 +01:00
|
|
|
setImageBackup.mediaLocation = null;
|
2015-05-03 13:48:36 +02:00
|
|
|
setImageBackup.thumb = null;
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
if (delegate != null) {
|
2019-03-03 21:40:48 +01:00
|
|
|
delegate.didSetImage(this, currentThumbDrawable != null || staticThumbDrawable != null, true);
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
2014-07-23 18:53:14 +02:00
|
|
|
if (parentView != null) {
|
2015-05-21 23:27:27 +02:00
|
|
|
if (invalidateAll) {
|
|
|
|
parentView.invalidate();
|
|
|
|
} else {
|
|
|
|
parentView.invalidate(imageX, imageY, imageX + imageW, imageY + imageH);
|
|
|
|
}
|
2014-07-23 18:53:14 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
if (forceCrossfade && crossfadeWithOldImage && crossfadeImage != null) {
|
|
|
|
currentAlpha = 0.0f;
|
|
|
|
lastUpdateAlphaTime = System.currentTimeMillis();
|
2019-03-03 21:40:48 +01:00
|
|
|
crossfadeWithThumb = currentThumbDrawable != null || staticThumbDrawable != null;
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
2014-03-31 16:14:49 +02:00
|
|
|
}
|
|
|
|
|
2014-02-04 19:36:55 +01:00
|
|
|
public void clearImage() {
|
2019-03-03 21:40:48 +01:00
|
|
|
for (int a = 0; a < 4; a++) {
|
2017-12-08 18:35:59 +01:00
|
|
|
recycleBitmap(null, a);
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
ImageLoader.getInstance().cancelLoadingForImageReceiver(this, true);
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
public void onDetachedFromWindow() {
|
2019-03-03 21:40:48 +01:00
|
|
|
if (currentImageLocation != null || currentMediaLocation != null || currentThumbLocation != null || staticThumbDrawable != null) {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (setImageBackup == null) {
|
|
|
|
setImageBackup = new SetImageBackup();
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
setImageBackup.mediaLocation = currentMediaLocation;
|
|
|
|
setImageBackup.mediaFilter = currentMediaFilter;
|
2015-05-03 13:48:36 +02:00
|
|
|
setImageBackup.fileLocation = currentImageLocation;
|
2019-03-03 21:40:48 +01:00
|
|
|
setImageBackup.filter = currentImageFilter;
|
|
|
|
setImageBackup.thumb = staticThumbDrawable;
|
2015-05-03 13:48:36 +02:00
|
|
|
setImageBackup.thumbLocation = currentThumbLocation;
|
|
|
|
setImageBackup.thumbFilter = currentThumbFilter;
|
|
|
|
setImageBackup.size = currentSize;
|
2015-05-21 23:27:27 +02:00
|
|
|
setImageBackup.ext = currentExt;
|
2017-07-23 14:56:38 +02:00
|
|
|
setImageBackup.cacheType = currentCacheType;
|
2019-01-23 18:03:33 +01:00
|
|
|
setImageBackup.parentObject = currentParentObject;
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didReplacedPhotoInMemCache);
|
2015-05-03 13:48:36 +02:00
|
|
|
clearImage();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean onAttachedToWindow() {
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didReplacedPhotoInMemCache);
|
2019-03-03 21:40:48 +01:00
|
|
|
if (setImageBackup != null && (setImageBackup.fileLocation != null || setImageBackup.thumbLocation != null || setImageBackup.mediaLocation != null || setImageBackup.thumb != null)) {
|
|
|
|
setImage(setImageBackup.mediaLocation, setImageBackup.mediaFilter, setImageBackup.fileLocation, setImageBackup.filter, setImageBackup.thumb, setImageBackup.thumbLocation, setImageBackup.thumbFilter, setImageBackup.size, setImageBackup.ext, setImageBackup.parentObject, setImageBackup.cacheType);
|
2015-05-03 13:48:36 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
private void drawDrawable(Canvas canvas, Drawable drawable, int alpha, BitmapShader shader, int orientation) {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (drawable instanceof BitmapDrawable) {
|
|
|
|
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
Paint paint;
|
|
|
|
if (shader != null) {
|
|
|
|
paint = roundPaint;
|
|
|
|
} else {
|
|
|
|
paint = bitmapDrawable.getPaint();
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
boolean hasFilter = paint != null && paint.getColorFilter() != null;
|
2017-12-08 18:35:59 +01:00
|
|
|
if (hasFilter && isPressed == 0) {
|
2016-04-22 15:49:00 +02:00
|
|
|
if (shader != null) {
|
|
|
|
roundPaint.setColorFilter(null);
|
2019-03-03 21:40:48 +01:00
|
|
|
} else if (staticThumbDrawable != drawable) {
|
2016-04-22 15:49:00 +02:00
|
|
|
bitmapDrawable.setColorFilter(null);
|
|
|
|
}
|
2017-12-08 18:35:59 +01:00
|
|
|
} else if (!hasFilter && isPressed != 0) {
|
|
|
|
if (isPressed == 1) {
|
|
|
|
if (shader != null) {
|
|
|
|
roundPaint.setColorFilter(selectedColorFilter);
|
|
|
|
} else {
|
|
|
|
bitmapDrawable.setColorFilter(selectedColorFilter);
|
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
} else {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (shader != null) {
|
|
|
|
roundPaint.setColorFilter(selectedGroupColorFilter);
|
|
|
|
} else {
|
|
|
|
bitmapDrawable.setColorFilter(selectedGroupColorFilter);
|
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
if (colorFilter != null) {
|
2016-04-22 15:49:00 +02:00
|
|
|
if (shader != null) {
|
|
|
|
roundPaint.setColorFilter(colorFilter);
|
|
|
|
} else {
|
|
|
|
bitmapDrawable.setColorFilter(colorFilter);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
|
|
|
int bitmapW;
|
|
|
|
int bitmapH;
|
|
|
|
if (bitmapDrawable instanceof AnimatedFileDrawable) {
|
2019-03-03 21:40:48 +01:00
|
|
|
if (orientation % 360 == 90 || orientation % 360 == 270) {
|
2015-05-03 13:48:36 +02:00
|
|
|
bitmapW = bitmapDrawable.getIntrinsicHeight();
|
|
|
|
bitmapH = bitmapDrawable.getIntrinsicWidth();
|
2014-05-17 01:05:49 +02:00
|
|
|
} else {
|
2015-05-03 13:48:36 +02:00
|
|
|
bitmapW = bitmapDrawable.getIntrinsicWidth();
|
|
|
|
bitmapH = bitmapDrawable.getIntrinsicHeight();
|
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
} else {
|
2019-03-03 21:40:48 +01:00
|
|
|
if (orientation % 360 == 90 || orientation % 360 == 270) {
|
2016-04-22 15:49:00 +02:00
|
|
|
bitmapW = bitmapDrawable.getBitmap().getHeight();
|
|
|
|
bitmapH = bitmapDrawable.getBitmap().getWidth();
|
|
|
|
} else {
|
|
|
|
bitmapW = bitmapDrawable.getBitmap().getWidth();
|
|
|
|
bitmapH = bitmapDrawable.getBitmap().getHeight();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
float scaleW = bitmapW / (float) imageW;
|
|
|
|
float scaleH = bitmapH / (float) imageH;
|
|
|
|
|
|
|
|
if (shader != null) {
|
|
|
|
roundPaint.setShader(shader);
|
|
|
|
float scale = Math.min(scaleW, scaleH);
|
|
|
|
roundRect.set(imageX, imageY, imageX + imageW, imageY + imageH);
|
|
|
|
shaderMatrix.reset();
|
2019-03-03 21:40:48 +01:00
|
|
|
if (Math.abs(scaleW - scaleH) > 0.0005f) {
|
2016-04-22 15:49:00 +02:00
|
|
|
if (bitmapW / scaleH > imageW) {
|
|
|
|
drawRegion.set(imageX - ((int) (bitmapW / scaleH) - imageW) / 2, imageY, imageX + ((int) (bitmapW / scaleH) + imageW) / 2, imageY + imageH);
|
|
|
|
} else {
|
|
|
|
drawRegion.set(imageX, imageY - ((int) (bitmapH / scaleW) - imageH) / 2, imageX + imageW, imageY + ((int) (bitmapH / scaleW) + imageH) / 2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
|
|
|
|
}
|
|
|
|
if (isVisible) {
|
2019-03-03 21:40:48 +01:00
|
|
|
if (Math.abs(scaleW - scaleH) > 0.0005f) {
|
|
|
|
int w = (int) Math.ceil(imageW * scale);
|
|
|
|
int h = (int) Math.ceil(imageH * scale);
|
2016-04-22 15:49:00 +02:00
|
|
|
bitmapRect.set((bitmapW - w) / 2, (bitmapH - h) / 2, (bitmapW + w) / 2, (bitmapH + h) / 2);
|
|
|
|
shaderMatrix.setRectToRect(bitmapRect, roundRect, Matrix.ScaleToFit.START);
|
|
|
|
} else {
|
|
|
|
bitmapRect.set(0, 0, bitmapW, bitmapH);
|
|
|
|
shaderMatrix.setRectToRect(bitmapRect, roundRect, Matrix.ScaleToFit.FILL);
|
|
|
|
}
|
|
|
|
shader.setLocalMatrix(shaderMatrix);
|
|
|
|
roundPaint.setAlpha(alpha);
|
|
|
|
canvas.drawRoundRect(roundRect, roundRadius, roundRadius, roundPaint);
|
|
|
|
}
|
|
|
|
} else {
|
2015-05-03 13:48:36 +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);
|
|
|
|
bitmapDrawable.setBounds(drawRegion);
|
2019-02-08 03:30:32 +01:00
|
|
|
if (isVisible) {
|
|
|
|
try {
|
|
|
|
bitmapDrawable.setAlpha(alpha);
|
|
|
|
bitmapDrawable.draw(canvas);
|
|
|
|
} catch (Exception e) {
|
2019-03-03 21:40:48 +01:00
|
|
|
onBitmapException(bitmapDrawable);
|
2019-02-08 03:30:32 +01:00
|
|
|
FileLog.e(e);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
canvas.restore();
|
|
|
|
} else {
|
|
|
|
if (Math.abs(scaleW - scaleH) > 0.00001f) {
|
2014-10-21 22:35:16 +02:00
|
|
|
canvas.save();
|
2015-05-03 13:48:36 +02:00
|
|
|
canvas.clipRect(imageX, imageY, imageX + imageW, imageY + imageH);
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
if (orientation % 360 != 0) {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (centerRotation) {
|
2019-03-03 21:40:48 +01:00
|
|
|
canvas.rotate(orientation, imageW / 2, imageH / 2);
|
2015-05-03 13:48:36 +02:00
|
|
|
} else {
|
2019-03-03 21:40:48 +01:00
|
|
|
canvas.rotate(orientation, 0, 0);
|
2014-10-01 21:55:24 +02:00
|
|
|
}
|
2014-07-10 02:15:58 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2016-05-25 23:49:47 +02:00
|
|
|
if (bitmapW / scaleH > imageW) {
|
|
|
|
bitmapW /= scaleH;
|
|
|
|
drawRegion.set(imageX - (bitmapW - imageW) / 2, imageY, imageX + (bitmapW + imageW) / 2, imageY + imageH);
|
2015-05-03 13:48:36 +02:00
|
|
|
} else {
|
2016-05-25 23:49:47 +02:00
|
|
|
bitmapH /= scaleW;
|
|
|
|
drawRegion.set(imageX, imageY - (bitmapH - imageH) / 2, imageX + imageW, imageY + (bitmapH + imageH) / 2);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (bitmapDrawable instanceof AnimatedFileDrawable) {
|
|
|
|
((AnimatedFileDrawable) bitmapDrawable).setActualDrawRect(imageX, imageY, imageW, imageH);
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
if (orientation % 360 == 90 || orientation % 360 == 270) {
|
2015-05-03 13:48:36 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
if (isVisible) {
|
|
|
|
try {
|
|
|
|
bitmapDrawable.setAlpha(alpha);
|
|
|
|
bitmapDrawable.draw(canvas);
|
|
|
|
} catch (Exception e) {
|
2019-03-03 21:40:48 +01:00
|
|
|
onBitmapException(bitmapDrawable);
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
canvas.restore();
|
|
|
|
} else {
|
|
|
|
canvas.save();
|
2019-03-03 21:40:48 +01:00
|
|
|
if (orientation % 360 != 0) {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (centerRotation) {
|
2019-03-03 21:40:48 +01:00
|
|
|
canvas.rotate(orientation, imageW / 2, imageH / 2);
|
2015-02-26 02:32:51 +01:00
|
|
|
} else {
|
2019-03-03 21:40:48 +01:00
|
|
|
canvas.rotate(orientation, 0, 0);
|
2014-10-21 22:35:16 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
|
2017-03-31 01:58:05 +02:00
|
|
|
if (bitmapDrawable instanceof AnimatedFileDrawable) {
|
|
|
|
((AnimatedFileDrawable) bitmapDrawable).setActualDrawRect(imageX, imageY, imageW, imageH);
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
if (orientation % 360 == 90 || orientation % 360 == 270) {
|
2015-05-03 13:48:36 +02:00
|
|
|
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);
|
2014-10-21 22:35:16 +02:00
|
|
|
} else {
|
2015-05-03 13:48:36 +02:00
|
|
|
bitmapDrawable.setBounds(drawRegion);
|
|
|
|
}
|
|
|
|
if (isVisible) {
|
|
|
|
try {
|
|
|
|
bitmapDrawable.setAlpha(alpha);
|
|
|
|
bitmapDrawable.draw(canvas);
|
|
|
|
} catch (Exception e) {
|
2019-03-03 21:40:48 +01:00
|
|
|
onBitmapException(bitmapDrawable);
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
canvas.restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
|
|
|
|
drawable.setBounds(drawRegion);
|
|
|
|
if (isVisible) {
|
|
|
|
try {
|
|
|
|
drawable.setAlpha(alpha);
|
|
|
|
drawable.draw(canvas);
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
private void onBitmapException(Drawable bitmapDrawable) {
|
|
|
|
if (bitmapDrawable == currentMediaDrawable && currentMediaKey != null) {
|
|
|
|
ImageLoader.getInstance().removeImage(currentMediaKey);
|
|
|
|
currentMediaKey = null;
|
|
|
|
} else if (bitmapDrawable == currentImageDrawable && currentImageKey != null) {
|
|
|
|
ImageLoader.getInstance().removeImage(currentImageKey);
|
|
|
|
currentImageKey = null;
|
|
|
|
} else if (bitmapDrawable == currentThumbDrawable && currentThumbKey != null) {
|
|
|
|
ImageLoader.getInstance().removeImage(currentThumbKey);
|
|
|
|
currentThumbKey = null;
|
|
|
|
}
|
|
|
|
setImage(currentMediaLocation, currentMediaFilter, currentImageLocation, currentImageFilter, currentThumbDrawable, currentThumbLocation, currentThumbFilter, currentSize, currentExt, currentParentObject, currentCacheType);
|
|
|
|
}
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
private void checkAlphaAnimation(boolean skip) {
|
2017-07-23 14:56:38 +02:00
|
|
|
if (manualAlphaAnimator) {
|
|
|
|
return;
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
if (currentAlpha != 1) {
|
2016-01-11 18:19:48 +01:00
|
|
|
if (!skip) {
|
|
|
|
long currentTime = System.currentTimeMillis();
|
2016-04-22 15:49:00 +02:00
|
|
|
long dt = currentTime - lastUpdateAlphaTime;
|
|
|
|
if (dt > 18) {
|
|
|
|
dt = 18;
|
|
|
|
}
|
|
|
|
currentAlpha += dt / 150.0f;
|
2016-01-11 18:19:48 +01:00
|
|
|
if (currentAlpha > 1) {
|
|
|
|
currentAlpha = 1;
|
2017-12-08 18:35:59 +01:00
|
|
|
if (crossfadeImage != null) {
|
|
|
|
recycleBitmap(null, 2);
|
|
|
|
crossfadeShader = null;
|
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
lastUpdateAlphaTime = System.currentTimeMillis();
|
|
|
|
if (parentView != null) {
|
2015-05-21 23:27:27 +02:00
|
|
|
if (invalidateAll) {
|
|
|
|
parentView.invalidate();
|
|
|
|
} else {
|
|
|
|
parentView.invalidate(imageX, imageY, imageX + imageW, imageY + imageH);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean draw(Canvas canvas) {
|
|
|
|
try {
|
2016-01-11 18:19:48 +01:00
|
|
|
Drawable drawable = null;
|
2019-03-03 21:40:48 +01:00
|
|
|
AnimatedFileDrawable animation = getAnimation();
|
|
|
|
boolean animationNotReady = animation != null && !animation.hasBitmap();
|
|
|
|
int orientation = 0;
|
|
|
|
BitmapShader shaderToUse = null;
|
|
|
|
if (!forcePreview && currentMediaDrawable != null && !animationNotReady) {
|
|
|
|
drawable = currentMediaDrawable;
|
|
|
|
shaderToUse = mediaShader;
|
|
|
|
orientation = imageOrientation;
|
|
|
|
} else if (!forcePreview && currentImageDrawable != null && (!animationNotReady || currentMediaDrawable != null)) {
|
|
|
|
drawable = currentImageDrawable;
|
|
|
|
shaderToUse = imageShader;
|
|
|
|
orientation = imageOrientation;
|
|
|
|
animationNotReady = false;
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (crossfadeImage != null && !crossfadingWithThumb) {
|
2017-12-08 18:35:59 +01:00
|
|
|
drawable = crossfadeImage;
|
2019-03-03 21:40:48 +01:00
|
|
|
shaderToUse = crossfadeShader;
|
|
|
|
orientation = imageOrientation;
|
|
|
|
} else if (staticThumbDrawable instanceof BitmapDrawable) {
|
|
|
|
drawable = staticThumbDrawable;
|
|
|
|
shaderToUse = thumbShader;
|
|
|
|
orientation = thumbOrientation;
|
|
|
|
} else if (currentThumbDrawable != null) {
|
|
|
|
drawable = currentThumbDrawable;
|
|
|
|
shaderToUse = thumbShader;
|
|
|
|
orientation = thumbOrientation;
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
if (drawable != null) {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (crossfadeAlpha != 0) {
|
2016-01-11 18:19:48 +01:00
|
|
|
if (crossfadeWithThumb && animationNotReady) {
|
2019-03-03 21:40:48 +01:00
|
|
|
drawDrawable(canvas, drawable, (int) (overrideAlpha * 255), shaderToUse, orientation);
|
2016-01-11 18:19:48 +01:00
|
|
|
} else {
|
|
|
|
if (crossfadeWithThumb && currentAlpha != 1.0f) {
|
|
|
|
Drawable thumbDrawable = null;
|
2019-03-03 21:40:48 +01:00
|
|
|
BitmapShader thumbShaderToUse = null;
|
|
|
|
if (drawable == currentImageDrawable || drawable == currentMediaDrawable) {
|
2017-12-08 18:35:59 +01:00
|
|
|
if (crossfadeImage != null) {
|
|
|
|
thumbDrawable = crossfadeImage;
|
2019-03-03 21:40:48 +01:00
|
|
|
thumbShaderToUse = crossfadeShader;
|
|
|
|
} else if (currentThumbDrawable != null) {
|
|
|
|
thumbDrawable = currentThumbDrawable;
|
|
|
|
thumbShaderToUse = thumbShader;
|
|
|
|
} else if (staticThumbDrawable != null) {
|
|
|
|
thumbDrawable = staticThumbDrawable;
|
|
|
|
thumbShaderToUse = thumbShader;
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
} else if (drawable == currentThumbDrawable || drawable == crossfadeImage) {
|
|
|
|
if (staticThumbDrawable != null) {
|
|
|
|
thumbDrawable = staticThumbDrawable;
|
|
|
|
thumbShaderToUse = thumbShader;
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
} else if (drawable == staticThumbDrawable) {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (crossfadeImage != null) {
|
|
|
|
thumbDrawable = crossfadeImage;
|
2019-03-03 21:40:48 +01:00
|
|
|
thumbShaderToUse = crossfadeShader;
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
if (thumbDrawable != null) {
|
2019-03-03 21:40:48 +01:00
|
|
|
drawDrawable(canvas, thumbDrawable, (int) (overrideAlpha * 255), thumbShaderToUse, thumbOrientation);
|
2014-10-01 21:55:24 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
drawDrawable(canvas, drawable, (int) (overrideAlpha * currentAlpha * 255), shaderToUse, orientation);
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} else {
|
2019-03-03 21:40:48 +01:00
|
|
|
drawDrawable(canvas, drawable, (int) (overrideAlpha * 255), shaderToUse, orientation);
|
2014-05-17 01:05:49 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
checkAlphaAnimation(animationNotReady && crossfadeWithThumb);
|
2014-08-29 23:06:04 +02:00
|
|
|
return true;
|
2019-03-03 21:40:48 +01:00
|
|
|
} else if (staticThumbDrawable != null) {
|
|
|
|
drawDrawable(canvas, staticThumbDrawable, (int) (overrideAlpha * 255), null, thumbOrientation);
|
2016-01-11 18:19:48 +01:00
|
|
|
checkAlphaAnimation(animationNotReady);
|
2014-08-29 23:06:04 +02:00
|
|
|
return true;
|
2016-01-11 18:19:48 +01:00
|
|
|
} else {
|
|
|
|
checkAlphaAnimation(animationNotReady);
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
2014-08-29 23:06:04 +02:00
|
|
|
return false;
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
public void setManualAlphaAnimator(boolean value) {
|
|
|
|
manualAlphaAnimator = value;
|
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
public float getCurrentAlpha() {
|
|
|
|
return currentAlpha;
|
|
|
|
}
|
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
public void setCurrentAlpha(float value) {
|
|
|
|
currentAlpha = value;
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public Drawable getDrawable() {
|
2019-03-03 21:40:48 +01:00
|
|
|
if (currentMediaDrawable != null) {
|
|
|
|
return currentMediaDrawable;
|
|
|
|
} else if (currentImageDrawable != null) {
|
|
|
|
return currentImageDrawable;
|
|
|
|
} else if (currentThumbDrawable != null) {
|
|
|
|
return currentThumbDrawable;
|
|
|
|
} else if (staticThumbDrawable != null) {
|
|
|
|
return staticThumbDrawable;
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-06-07 01:35:21 +02:00
|
|
|
public Bitmap getBitmap() {
|
2019-03-03 21:40:48 +01:00
|
|
|
AnimatedFileDrawable animation = getAnimation();
|
|
|
|
if (animation != null && animation.hasBitmap()) {
|
|
|
|
return animation.getAnimatedBitmap();
|
|
|
|
} else if (currentMediaDrawable instanceof BitmapDrawable && !(currentMediaDrawable instanceof AnimatedFileDrawable)) {
|
|
|
|
return ((BitmapDrawable) currentMediaDrawable).getBitmap();
|
|
|
|
} else if (currentImageDrawable instanceof BitmapDrawable && !(currentImageDrawable instanceof AnimatedFileDrawable)) {
|
|
|
|
return ((BitmapDrawable) currentImageDrawable).getBitmap();
|
|
|
|
} else if (currentThumbDrawable instanceof BitmapDrawable && !(currentThumbDrawable instanceof AnimatedFileDrawable)) {
|
|
|
|
return ((BitmapDrawable) currentThumbDrawable).getBitmap();
|
|
|
|
} else if (staticThumbDrawable instanceof BitmapDrawable) {
|
|
|
|
return ((BitmapDrawable) staticThumbDrawable).getBitmap();
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public BitmapHolder getBitmapSafe() {
|
|
|
|
Bitmap bitmap = null;
|
|
|
|
String key = null;
|
2019-03-03 21:40:48 +01:00
|
|
|
AnimatedFileDrawable animation = getAnimation();
|
|
|
|
if (animation != null && animation.hasBitmap()) {
|
|
|
|
bitmap = animation.getAnimatedBitmap();
|
|
|
|
} else if (currentMediaDrawable instanceof BitmapDrawable && !(currentMediaDrawable instanceof AnimatedFileDrawable)) {
|
|
|
|
bitmap = ((BitmapDrawable) currentMediaDrawable).getBitmap();
|
|
|
|
key = currentMediaKey;
|
|
|
|
} else if (currentImageDrawable instanceof BitmapDrawable && !(currentImageDrawable instanceof AnimatedFileDrawable)) {
|
|
|
|
bitmap = ((BitmapDrawable) currentImageDrawable).getBitmap();
|
|
|
|
key = currentImageKey;
|
|
|
|
} else if (currentThumbDrawable instanceof BitmapDrawable && !(currentThumbDrawable instanceof AnimatedFileDrawable)) {
|
|
|
|
bitmap = ((BitmapDrawable) currentThumbDrawable).getBitmap();
|
2018-07-30 04:07:02 +02:00
|
|
|
key = currentThumbKey;
|
2019-03-03 21:40:48 +01:00
|
|
|
} else if (staticThumbDrawable instanceof BitmapDrawable) {
|
|
|
|
bitmap = ((BitmapDrawable) staticThumbDrawable).getBitmap();
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
if (bitmap != null) {
|
|
|
|
return new BitmapHolder(bitmap, key);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
public Bitmap getThumbBitmap() {
|
2019-03-03 21:40:48 +01:00
|
|
|
if (currentThumbDrawable instanceof BitmapDrawable) {
|
|
|
|
return ((BitmapDrawable) currentThumbDrawable).getBitmap();
|
|
|
|
} else if (staticThumbDrawable instanceof BitmapDrawable) {
|
|
|
|
return ((BitmapDrawable) staticThumbDrawable).getBitmap();
|
2017-07-23 14:56:38 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public BitmapHolder getThumbBitmapSafe() {
|
|
|
|
Bitmap bitmap = null;
|
|
|
|
String key = null;
|
2019-03-03 21:40:48 +01:00
|
|
|
if (currentThumbDrawable instanceof BitmapDrawable) {
|
|
|
|
bitmap = ((BitmapDrawable) currentThumbDrawable).getBitmap();
|
2018-07-30 04:07:02 +02:00
|
|
|
key = currentThumbKey;
|
2019-03-03 21:40:48 +01:00
|
|
|
} else if (staticThumbDrawable instanceof BitmapDrawable) {
|
|
|
|
bitmap = ((BitmapDrawable) staticThumbDrawable).getBitmap();
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
if (bitmap != null) {
|
|
|
|
return new BitmapHolder(bitmap, key);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
public int getBitmapWidth() {
|
2019-03-03 21:40:48 +01:00
|
|
|
AnimatedFileDrawable animation = getAnimation();
|
|
|
|
if (animation != null) {
|
|
|
|
return imageOrientation % 360 == 0 || imageOrientation % 360 == 180 ? animation.getIntrinsicWidth() : animation.getIntrinsicHeight();
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
Bitmap bitmap = getBitmap();
|
2017-07-08 18:32:04 +02:00
|
|
|
if (bitmap == null) {
|
2019-03-03 21:40:48 +01:00
|
|
|
if (staticThumbDrawable != null) {
|
|
|
|
return staticThumbDrawable.getIntrinsicWidth();
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
return imageOrientation % 360 == 0 || imageOrientation % 360 == 180 ? bitmap.getWidth() : bitmap.getHeight();
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getBitmapHeight() {
|
2019-03-03 21:40:48 +01:00
|
|
|
AnimatedFileDrawable animation = getAnimation();
|
|
|
|
if (animation != null) {
|
|
|
|
return imageOrientation % 360 == 0 || imageOrientation % 360 == 180 ? animation.getIntrinsicHeight() : animation.getIntrinsicWidth();
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
Bitmap bitmap = getBitmap();
|
2017-07-08 18:32:04 +02:00
|
|
|
if (bitmap == null) {
|
2019-03-03 21:40:48 +01:00
|
|
|
if (staticThumbDrawable != null) {
|
|
|
|
return staticThumbDrawable.getIntrinsicHeight();
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
return imageOrientation % 360 == 0 || imageOrientation % 360 == 180 ? bitmap.getHeight() : bitmap.getWidth();
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
|
2014-06-11 01:05:54 +02:00
|
|
|
public void setVisible(boolean value, boolean invalidate) {
|
2014-06-07 01:35:21 +02:00
|
|
|
if (isVisible == value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
isVisible = value;
|
2014-06-12 21:55:13 +02:00
|
|
|
if (invalidate && parentView != null) {
|
2015-05-21 23:27:27 +02:00
|
|
|
if (invalidateAll) {
|
|
|
|
parentView.invalidate();
|
|
|
|
} else {
|
|
|
|
parentView.invalidate(imageX, imageY, imageX + imageW, imageY + imageH);
|
|
|
|
}
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getVisible() {
|
|
|
|
return isVisible;
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
public void setAlpha(float value) {
|
2015-05-03 13:48:36 +02:00
|
|
|
overrideAlpha = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCrossfadeAlpha(byte value) {
|
|
|
|
crossfadeAlpha = value;
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
public boolean hasImageSet() {
|
|
|
|
return currentImageDrawable != null || currentMediaDrawable != null || currentThumbDrawable != null || staticThumbDrawable != null || currentImageKey != null || currentMediaKey != null;
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
public boolean hasBitmapImage() {
|
2019-03-03 21:40:48 +01:00
|
|
|
return currentImageDrawable != null || currentThumbDrawable != null || staticThumbDrawable != null || currentMediaDrawable != null;
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public boolean hasNotThumb() {
|
2019-03-03 21:40:48 +01:00
|
|
|
return currentImageDrawable != null || currentMediaDrawable != null;
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
|
2019-02-08 03:30:32 +01:00
|
|
|
public boolean hasStaticThumb() {
|
2019-03-03 21:40:48 +01:00
|
|
|
return staticThumbDrawable != null;
|
2019-02-08 03:30:32 +01:00
|
|
|
}
|
|
|
|
|
2014-08-22 16:24:33 +02:00
|
|
|
public void setAspectFit(boolean value) {
|
|
|
|
isAspectFit = value;
|
|
|
|
}
|
|
|
|
|
2019-02-08 03:30:32 +01:00
|
|
|
public boolean isAspectFit() {
|
|
|
|
return isAspectFit;
|
|
|
|
}
|
|
|
|
|
2014-08-22 16:24:33 +02:00
|
|
|
public void setParentView(View view) {
|
|
|
|
parentView = view;
|
2019-03-03 21:40:48 +01:00
|
|
|
AnimatedFileDrawable animation = getAnimation();
|
|
|
|
if (animation != null) {
|
|
|
|
animation.setParentView(parentView);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2014-08-22 16:24:33 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public void setImageX(int x) {
|
|
|
|
imageX = x;
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public void setImageY(int y) {
|
|
|
|
imageY = y;
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public void setImageWidth(int width) {
|
|
|
|
imageW = width;
|
|
|
|
}
|
|
|
|
|
2014-08-22 16:24:33 +02:00
|
|
|
public void setImageCoords(int x, int y, int width, int height) {
|
|
|
|
imageX = x;
|
|
|
|
imageY = y;
|
|
|
|
imageW = width;
|
|
|
|
imageH = height;
|
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
public float getCenterX() {
|
|
|
|
return imageX + imageW / 2.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
public float getCenterY() {
|
|
|
|
return imageY + imageH / 2.0f;
|
|
|
|
}
|
|
|
|
|
2014-08-22 16:24:33 +02:00
|
|
|
public int getImageX() {
|
|
|
|
return imageX;
|
|
|
|
}
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
public int getImageX2() {
|
|
|
|
return imageX + imageW;
|
|
|
|
}
|
|
|
|
|
2014-08-22 16:24:33 +02:00
|
|
|
public int getImageY() {
|
|
|
|
return imageY;
|
|
|
|
}
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
public int getImageY2() {
|
|
|
|
return imageY + imageH;
|
|
|
|
}
|
|
|
|
|
2014-08-22 16:24:33 +02:00
|
|
|
public int getImageWidth() {
|
|
|
|
return imageW;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getImageHeight() {
|
|
|
|
return imageH;
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public float getImageAspectRatio() {
|
2019-03-03 21:40:48 +01:00
|
|
|
return imageOrientation % 180 != 0 ? drawRegion.height() / (float) drawRegion.width() : drawRegion.width() / (float) drawRegion.height();
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
public String getExt() {
|
|
|
|
return currentExt;
|
|
|
|
}
|
|
|
|
|
2014-08-22 16:24:33 +02:00
|
|
|
public boolean isInsideImage(float x, float y) {
|
|
|
|
return x >= imageX && x <= imageX + imageW && y >= imageY && y <= imageY + imageH;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Rect getDrawRegion() {
|
|
|
|
return drawRegion;
|
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
public String getImageKey() {
|
|
|
|
return currentImageKey;
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
public String getImageFilter() {
|
|
|
|
return currentImageFilter;
|
2014-08-22 16:24:33 +02:00
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
public String getMediaKey() {
|
|
|
|
return currentMediaKey;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getMediaFilter() {
|
|
|
|
return currentMediaFilter;
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getThumbKey() {
|
|
|
|
return currentThumbKey;
|
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
public String getThumbFilter() {
|
|
|
|
return currentThumbFilter;
|
|
|
|
}
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
public int getSize() {
|
|
|
|
return currentSize;
|
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
public Object getMediaLocation() {
|
|
|
|
return currentMediaLocation;
|
|
|
|
}
|
|
|
|
|
2019-02-08 03:30:32 +01:00
|
|
|
public Object getImageLocation() {
|
2015-02-01 19:51:02 +01:00
|
|
|
return currentImageLocation;
|
|
|
|
}
|
|
|
|
|
2019-02-08 03:30:32 +01:00
|
|
|
public Object getThumbLocation() {
|
2015-02-01 19:51:02 +01:00
|
|
|
return currentThumbLocation;
|
|
|
|
}
|
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
public int getCacheType() {
|
|
|
|
return currentCacheType;
|
2014-08-22 16:24:33 +02:00
|
|
|
}
|
2014-10-09 17:55:05 +02:00
|
|
|
|
|
|
|
public void setForcePreview(boolean value) {
|
|
|
|
forcePreview = value;
|
|
|
|
}
|
2014-10-21 22:35:16 +02:00
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
public void setForceCrossfade(boolean value) {
|
|
|
|
forceCrossfade = value;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public void setCurrentAccount(int value) {
|
|
|
|
currentAccount = value;
|
|
|
|
}
|
|
|
|
|
2014-11-17 03:44:57 +01:00
|
|
|
public int getRoundRadius() {
|
|
|
|
return roundRadius;
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public Object getParentObject() {
|
|
|
|
return currentParentObject;
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setNeedsQualityThumb(boolean value) {
|
|
|
|
needsQualityThumb = value;
|
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
public void setQualityThumbDocument(TLRPC.Document document) {
|
|
|
|
qulityThumbDocument = document;
|
|
|
|
}
|
|
|
|
|
|
|
|
public TLRPC.Document getQulityThumbDocument() {
|
|
|
|
return qulityThumbDocument;
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public void setCrossfadeWithOldImage(boolean value) {
|
|
|
|
crossfadeWithOldImage = value;
|
|
|
|
}
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
public boolean isNeedsQualityThumb() {
|
|
|
|
return needsQualityThumb;
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public boolean isCurrentKeyQuality() {
|
|
|
|
return currentKeyQuality;
|
|
|
|
}
|
|
|
|
|
2019-02-08 03:30:32 +01:00
|
|
|
public int getCurrentAccount() {
|
2018-07-30 04:07:02 +02:00
|
|
|
return currentAccount;
|
|
|
|
}
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
public void setShouldGenerateQualityThumb(boolean value) {
|
|
|
|
shouldGenerateQualityThumb = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isShouldGenerateQualityThumb() {
|
|
|
|
return shouldGenerateQualityThumb;
|
|
|
|
}
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
public void setAllowStartAnimation(boolean value) {
|
|
|
|
allowStartAnimation = value;
|
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
public void setAllowDecodeSingleFrame(boolean value) {
|
|
|
|
allowDecodeSingleFrame = value;
|
|
|
|
}
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
public boolean isAllowStartAnimation() {
|
|
|
|
return allowStartAnimation;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void startAnimation() {
|
2019-03-03 21:40:48 +01:00
|
|
|
AnimatedFileDrawable animation = getAnimation();
|
|
|
|
if (animation != null) {
|
|
|
|
animation.start();
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void stopAnimation() {
|
2019-03-03 21:40:48 +01:00
|
|
|
AnimatedFileDrawable animation = getAnimation();
|
|
|
|
if (animation != null) {
|
|
|
|
animation.stop();
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isAnimationRunning() {
|
2019-03-03 21:40:48 +01:00
|
|
|
AnimatedFileDrawable animation = getAnimation();
|
|
|
|
return animation != null && animation.isRunning();
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
public AnimatedFileDrawable getAnimation() {
|
2019-03-03 21:40:48 +01:00
|
|
|
AnimatedFileDrawable animatedFileDrawable;
|
|
|
|
if (currentMediaDrawable instanceof AnimatedFileDrawable) {
|
|
|
|
return (AnimatedFileDrawable) currentMediaDrawable;
|
|
|
|
} else if (currentImageDrawable instanceof AnimatedFileDrawable) {
|
|
|
|
return (AnimatedFileDrawable) currentImageDrawable;
|
|
|
|
} else if (currentThumbDrawable instanceof AnimatedFileDrawable) {
|
|
|
|
return (AnimatedFileDrawable) currentThumbDrawable;
|
|
|
|
} else if (staticThumbDrawable instanceof AnimatedFileDrawable) {
|
|
|
|
return (AnimatedFileDrawable) staticThumbDrawable;
|
|
|
|
}
|
|
|
|
return null;
|
2016-06-24 12:27:15 +02:00
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
protected int getTag(int type) {
|
|
|
|
if (type == TYPE_THUMB) {
|
2015-02-01 19:51:02 +01:00
|
|
|
return thumbTag;
|
2019-03-03 21:40:48 +01:00
|
|
|
} else if (type == TYPE_MEDIA) {
|
|
|
|
return mediaTag;
|
2015-02-01 19:51:02 +01:00
|
|
|
} else {
|
2019-03-03 21:40:48 +01:00
|
|
|
return imageTag;
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
protected void setTag(int value, int type) {
|
|
|
|
if (type == TYPE_THUMB) {
|
2015-02-01 19:51:02 +01:00
|
|
|
thumbTag = value;
|
2019-03-03 21:40:48 +01:00
|
|
|
} else if (type == TYPE_MEDIA) {
|
|
|
|
mediaTag = value;
|
2015-02-01 19:51:02 +01:00
|
|
|
} else {
|
2019-03-03 21:40:48 +01:00
|
|
|
imageTag = value;
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public void setParam(int value) {
|
|
|
|
param = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getParam() {
|
|
|
|
return param;
|
|
|
|
}
|
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
protected boolean setImageBitmapByKey(BitmapDrawable bitmap, String key, int type, boolean memCache) {
|
2015-02-01 19:51:02 +01:00
|
|
|
if (bitmap == null || key == null) {
|
2016-01-11 18:19:48 +01:00
|
|
|
return false;
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
if (type == TYPE_IMAGE) {
|
|
|
|
if (!key.equals(currentImageKey)) {
|
2016-01-11 18:19:48 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!(bitmap instanceof AnimatedFileDrawable)) {
|
2019-03-03 21:40:48 +01:00
|
|
|
ImageLoader.getInstance().incrementUseCount(currentImageKey);
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
currentImageDrawable = bitmap;
|
2019-01-23 18:03:33 +01:00
|
|
|
if (bitmap instanceof ExtendedBitmapDrawable) {
|
2019-03-03 21:40:48 +01:00
|
|
|
imageOrientation = ((ExtendedBitmapDrawable) bitmap).getOrientation();
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
if (roundRadius != 0 && bitmap instanceof BitmapDrawable) {
|
|
|
|
if (bitmap instanceof AnimatedFileDrawable) {
|
|
|
|
((AnimatedFileDrawable) bitmap).setRoundRadius(roundRadius);
|
|
|
|
} else {
|
|
|
|
Bitmap object = bitmap.getBitmap();
|
2019-03-03 21:40:48 +01:00
|
|
|
imageShader = new BitmapShader(object, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
|
|
|
} else {
|
2019-03-03 21:40:48 +01:00
|
|
|
imageShader = null;
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2017-07-23 14:56:38 +02:00
|
|
|
if (!memCache && !forcePreview || forceCrossfade) {
|
2019-03-03 21:40:48 +01:00
|
|
|
boolean allowCorssfade = true;
|
|
|
|
if (currentMediaDrawable instanceof AnimatedFileDrawable && ((AnimatedFileDrawable) currentMediaDrawable).hasBitmap()) {
|
|
|
|
allowCorssfade = false;
|
|
|
|
}
|
|
|
|
if (allowCorssfade && (currentThumbDrawable == null && staticThumbDrawable == null || currentAlpha == 1.0f || forceCrossfade)) {
|
2015-05-03 13:48:36 +02:00
|
|
|
currentAlpha = 0.0f;
|
|
|
|
lastUpdateAlphaTime = System.currentTimeMillis();
|
2019-03-03 21:40:48 +01:00
|
|
|
crossfadeWithThumb = crossfadeImage != null || currentThumbDrawable != null || staticThumbDrawable != null;
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
currentAlpha = 1.0f;
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
} else if (type == TYPE_MEDIA) {
|
|
|
|
if (!key.equals(currentMediaKey)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!(bitmap instanceof AnimatedFileDrawable)) {
|
|
|
|
ImageLoader.getInstance().incrementUseCount(currentMediaKey);
|
|
|
|
}
|
|
|
|
currentMediaDrawable = bitmap;
|
|
|
|
if (roundRadius != 0 && bitmap instanceof BitmapDrawable) {
|
|
|
|
if (bitmap instanceof AnimatedFileDrawable) {
|
|
|
|
((AnimatedFileDrawable) bitmap).setRoundRadius(roundRadius);
|
2017-07-08 18:32:04 +02:00
|
|
|
} else {
|
2019-03-03 21:40:48 +01:00
|
|
|
Bitmap object = bitmap.getBitmap();
|
|
|
|
mediaShader = new BitmapShader(object, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
} else {
|
|
|
|
mediaShader = null;
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
if (currentImageDrawable == null) {
|
|
|
|
if (!memCache && !forcePreview || forceCrossfade) {
|
|
|
|
if (currentThumbDrawable == null && staticThumbDrawable == null || currentAlpha == 1.0f || forceCrossfade) {
|
|
|
|
currentAlpha = 0.0f;
|
|
|
|
lastUpdateAlphaTime = System.currentTimeMillis();
|
|
|
|
crossfadeWithThumb = crossfadeImage != null || currentThumbDrawable != null || staticThumbDrawable != null;
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
} else {
|
2019-03-03 21:40:48 +01:00
|
|
|
currentAlpha = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (type == TYPE_THUMB) {
|
|
|
|
if (currentThumbDrawable != null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!forcePreview) {
|
|
|
|
AnimatedFileDrawable animation = getAnimation();
|
|
|
|
if (animation != null && animation.hasBitmap()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (currentImageDrawable != null && !(currentImageDrawable instanceof AnimatedFileDrawable) || currentMediaDrawable != null && !(currentMediaDrawable instanceof AnimatedFileDrawable)) {
|
|
|
|
return false;
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
if (!key.equals(currentThumbKey)) {
|
2016-01-11 18:19:48 +01:00
|
|
|
return false;
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
ImageLoader.getInstance().incrementUseCount(currentThumbKey);
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
currentThumbDrawable = bitmap;
|
2019-01-23 18:03:33 +01:00
|
|
|
if (bitmap instanceof ExtendedBitmapDrawable) {
|
|
|
|
thumbOrientation = ((ExtendedBitmapDrawable) bitmap).getOrientation();
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
if (roundRadius != 0 && bitmap instanceof BitmapDrawable) {
|
2016-04-22 15:49:00 +02:00
|
|
|
if (bitmap instanceof AnimatedFileDrawable) {
|
|
|
|
((AnimatedFileDrawable) bitmap).setRoundRadius(roundRadius);
|
|
|
|
} else {
|
|
|
|
Bitmap object = bitmap.getBitmap();
|
2019-03-03 21:40:48 +01:00
|
|
|
thumbShader = new BitmapShader(object, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
|
|
|
} else {
|
2019-03-03 21:40:48 +01:00
|
|
|
thumbShader = null;
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
if (!memCache && crossfadeAlpha != 2) {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (currentParentObject instanceof MessageObject && ((MessageObject) currentParentObject).isRoundVideo() && ((MessageObject) currentParentObject).isSending()) {
|
2017-07-08 18:32:04 +02:00
|
|
|
currentAlpha = 1.0f;
|
|
|
|
} else {
|
|
|
|
currentAlpha = 0.0f;
|
|
|
|
lastUpdateAlphaTime = System.currentTimeMillis();
|
2019-03-03 21:40:48 +01:00
|
|
|
crossfadeWithThumb = staticThumbDrawable != null && currentImageKey == null && currentMediaKey == null;
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} else {
|
|
|
|
currentAlpha = 1.0f;
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
}
|
|
|
|
if (bitmap instanceof AnimatedFileDrawable) {
|
|
|
|
AnimatedFileDrawable fileDrawable = (AnimatedFileDrawable) bitmap;
|
|
|
|
fileDrawable.setParentView(parentView);
|
|
|
|
if (allowStartAnimation) {
|
|
|
|
fileDrawable.start();
|
|
|
|
}
|
|
|
|
fileDrawable.setAllowDecodeSingleFrame(allowDecodeSingleFrame);
|
|
|
|
}
|
|
|
|
if (parentView != null) {
|
|
|
|
if (invalidateAll) {
|
|
|
|
parentView.invalidate();
|
|
|
|
} else {
|
|
|
|
parentView.invalidate(imageX, imageY, imageX + imageW, imageY + imageH);
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (delegate != null) {
|
2019-03-03 21:40:48 +01:00
|
|
|
delegate.didSetImage(this, currentImageDrawable != null || currentThumbDrawable != null || staticThumbDrawable != null || currentMediaDrawable != null, currentImageDrawable == null && currentMediaDrawable == null);
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
return true;
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
private void recycleBitmap(String newKey, int type) {
|
2015-02-01 19:51:02 +01:00
|
|
|
String key;
|
2016-01-11 18:19:48 +01:00
|
|
|
Drawable image;
|
2019-03-03 21:40:48 +01:00
|
|
|
if (type == TYPE_MEDIA) {
|
|
|
|
key = currentMediaKey;
|
|
|
|
image = currentMediaDrawable;
|
|
|
|
} else if (type == TYPE_CROSSFDADE) {
|
2017-12-08 18:35:59 +01:00
|
|
|
key = crossfadeKey;
|
|
|
|
image = crossfadeImage;
|
2019-03-03 21:40:48 +01:00
|
|
|
} else if (type == TYPE_THUMB) {
|
2015-02-01 19:51:02 +01:00
|
|
|
key = currentThumbKey;
|
2019-03-03 21:40:48 +01:00
|
|
|
image = currentThumbDrawable;
|
2015-02-01 19:51:02 +01:00
|
|
|
} else {
|
2019-03-03 21:40:48 +01:00
|
|
|
key = currentImageKey;
|
|
|
|
image = currentImageDrawable;
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (key != null && key.startsWith("-")) {
|
|
|
|
String replacedKey = ImageLoader.getInstance().getReplacedKey(key);
|
|
|
|
if (replacedKey != null) {
|
|
|
|
key = replacedKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String replacedKey = ImageLoader.getInstance().getReplacedKey(key);
|
2016-01-11 18:19:48 +01:00
|
|
|
if (key != null && (newKey == null || !newKey.equals(key)) && image != null) {
|
|
|
|
if (image instanceof AnimatedFileDrawable) {
|
|
|
|
AnimatedFileDrawable fileDrawable = (AnimatedFileDrawable) image;
|
|
|
|
fileDrawable.recycle();
|
|
|
|
} else if (image instanceof BitmapDrawable) {
|
|
|
|
Bitmap bitmap = ((BitmapDrawable) image).getBitmap();
|
|
|
|
boolean canDelete = ImageLoader.getInstance().decrementUseCount(key);
|
|
|
|
if (!ImageLoader.getInstance().isInCache(key)) {
|
|
|
|
if (canDelete) {
|
|
|
|
bitmap.recycle();
|
|
|
|
}
|
2015-09-24 22:52:02 +02:00
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
if (type == TYPE_MEDIA) {
|
|
|
|
currentMediaKey = null;
|
|
|
|
currentMediaDrawable = null;
|
|
|
|
} else if (type == TYPE_CROSSFDADE) {
|
2017-12-08 18:35:59 +01:00
|
|
|
crossfadeKey = null;
|
|
|
|
crossfadeImage = null;
|
2019-03-03 21:40:48 +01:00
|
|
|
} else if (type == TYPE_THUMB) {
|
|
|
|
currentThumbDrawable = null;
|
2015-02-01 19:51:02 +01:00
|
|
|
currentThumbKey = null;
|
|
|
|
} else {
|
2019-03-03 21:40:48 +01:00
|
|
|
currentImageDrawable = null;
|
|
|
|
currentImageKey = null;
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-07-30 04:07:02 +02:00
|
|
|
public void didReceivedNotification(int id, int account, Object... args) {
|
2019-01-23 18:03:33 +01:00
|
|
|
if (id == NotificationCenter.didReplacedPhotoInMemCache) {
|
2015-05-03 13:48:36 +02:00
|
|
|
String oldKey = (String) args[0];
|
2019-03-03 21:40:48 +01:00
|
|
|
if (currentMediaKey != null && currentMediaKey.equals(oldKey)) {
|
|
|
|
currentMediaKey = (String) args[1];
|
|
|
|
currentMediaLocation = args[2];
|
|
|
|
if (setImageBackup != null) {
|
|
|
|
setImageBackup.mediaLocation = args[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentImageKey != null && currentImageKey.equals(oldKey)) {
|
|
|
|
currentImageKey = (String) args[1];
|
2019-02-08 03:30:32 +01:00
|
|
|
currentImageLocation = args[2];
|
2019-03-03 21:40:48 +01:00
|
|
|
if (setImageBackup != null) {
|
|
|
|
setImageBackup.fileLocation = args[2];
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
if (currentThumbKey != null && currentThumbKey.equals(oldKey)) {
|
|
|
|
currentThumbKey = (String) args[1];
|
2019-02-08 03:30:32 +01:00
|
|
|
currentThumbLocation = args[2];
|
2019-03-03 21:40:48 +01:00
|
|
|
if (setImageBackup != null) {
|
|
|
|
setImageBackup.thumbLocation = args[2];
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|