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;
|
2021-06-25 02:43:10 +02:00
|
|
|
import android.graphics.BlendMode;
|
2014-02-04 19:36:55 +01:00
|
|
|
import android.graphics.Canvas;
|
2015-05-03 13:48:36 +02:00
|
|
|
import android.graphics.ColorFilter;
|
2021-06-25 02:43:10 +02:00
|
|
|
import android.graphics.ComposeShader;
|
2014-10-21 22:35:16 +02:00
|
|
|
import android.graphics.Matrix;
|
|
|
|
import android.graphics.Paint;
|
2020-01-23 07:15:40 +01:00
|
|
|
import android.graphics.Path;
|
2015-01-02 23:15:07 +01:00
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
import android.graphics.PorterDuffColorFilter;
|
2021-06-25 02:43:10 +02:00
|
|
|
import android.graphics.PorterDuffXfermode;
|
2022-06-21 04:51:00 +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;
|
2021-06-25 02:43:10 +02:00
|
|
|
import android.os.Build;
|
2014-02-04 19:36:55 +01:00
|
|
|
import android.view.View;
|
|
|
|
|
2022-01-10 03:27:47 +01:00
|
|
|
import androidx.annotation.Keep;
|
|
|
|
|
2021-04-17 01:59:59 +02:00
|
|
|
import org.telegram.tgnet.TLObject;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.TLRPC;
|
2016-01-11 18:19:48 +01:00
|
|
|
import org.telegram.ui.Components.AnimatedFileDrawable;
|
2022-11-05 13:34:47 +01:00
|
|
|
import org.telegram.ui.Components.AvatarDrawable;
|
2022-11-06 02:16:18 +01:00
|
|
|
import org.telegram.ui.Components.ClipRoundedDrawable;
|
|
|
|
import org.telegram.ui.Components.CubicBezierInterpolator;
|
2020-09-30 15:48:47 +02:00
|
|
|
import org.telegram.ui.Components.LoadingStickerDrawable;
|
2019-07-18 15:01:39 +02:00
|
|
|
import org.telegram.ui.Components.RLottieDrawable;
|
2019-01-23 18:03:33 +01:00
|
|
|
import org.telegram.ui.Components.RecyclableDrawable;
|
2014-02-04 19:36:55 +01:00
|
|
|
|
2021-11-05 11:06:49 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
public class ImageReceiver implements NotificationCenter.NotificationCenterDelegate {
|
|
|
|
|
2022-12-06 20:13:44 +01:00
|
|
|
public boolean updateThumbShaderMatrix() {
|
|
|
|
if (currentThumbDrawable != null && thumbShader != null) {
|
|
|
|
drawDrawable(null, currentThumbDrawable, 255, thumbShader, 0, 0, null);
|
|
|
|
return true;
|
2022-12-30 13:32:20 +01:00
|
|
|
}
|
|
|
|
if (staticThumbDrawable != null && thumbShader != null) {
|
2022-12-06 20:13:44 +01:00
|
|
|
drawDrawable(null, staticThumbDrawable, 255, thumbShader, 0, 0, null);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-19 00:09:45 +01:00
|
|
|
public interface ImageReceiverDelegate {
|
2020-03-30 14:00:09 +02:00
|
|
|
void didSetImage(ImageReceiver imageReceiver, boolean set, boolean thumb, boolean memCache);
|
2021-04-17 01:59:59 +02:00
|
|
|
|
2019-08-22 01:53:26 +02:00
|
|
|
default void onAnimationReady(ImageReceiver imageReceiver) {
|
|
|
|
}
|
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;
|
2020-07-26 10:03:38 +02:00
|
|
|
public Drawable drawable;
|
|
|
|
public int orientation;
|
2018-07-30 04:07:02 +02:00
|
|
|
|
2020-07-26 10:03:38 +02:00
|
|
|
public BitmapHolder(Bitmap b, String k, int o) {
|
2018-07-30 04:07:02 +02:00
|
|
|
bitmap = b;
|
|
|
|
key = k;
|
2020-07-26 10:03:38 +02:00
|
|
|
orientation = o;
|
|
|
|
if (key != null) {
|
|
|
|
ImageLoader.getInstance().incrementUseCount(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public BitmapHolder(Drawable d, String k, int o) {
|
|
|
|
drawable = d;
|
|
|
|
key = k;
|
|
|
|
orientation = o;
|
2018-07-30 04:07:02 +02:00
|
|
|
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;
|
2020-07-26 10:03:38 +02:00
|
|
|
drawable = null;
|
2018-07-30 04:07:02 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
boolean canDelete = ImageLoader.getInstance().decrementUseCount(key);
|
2019-07-18 15:01:39 +02:00
|
|
|
if (!ImageLoader.getInstance().isInMemCache(key, false)) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (canDelete) {
|
2020-07-26 10:03:38 +02:00
|
|
|
if (bitmap != null) {
|
|
|
|
bitmap.recycle();
|
|
|
|
} else if (drawable != null) {
|
|
|
|
if (drawable instanceof RLottieDrawable) {
|
|
|
|
RLottieDrawable fileDrawable = (RLottieDrawable) drawable;
|
|
|
|
fileDrawable.recycle();
|
|
|
|
} else if (drawable instanceof AnimatedFileDrawable) {
|
|
|
|
AnimatedFileDrawable fileDrawable = (AnimatedFileDrawable) drawable;
|
|
|
|
fileDrawable.recycle();
|
|
|
|
} else if (drawable instanceof BitmapDrawable) {
|
|
|
|
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
|
|
|
|
bitmap.recycle();
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
key = null;
|
|
|
|
bitmap = null;
|
2020-07-26 10:03:38 +02:00
|
|
|
drawable = null;
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
private static class SetImageBackup {
|
2019-05-14 14:08:05 +02:00
|
|
|
public ImageLocation imageLocation;
|
|
|
|
public String imageFilter;
|
|
|
|
public ImageLocation thumbLocation;
|
2015-05-03 13:48:36 +02:00
|
|
|
public String thumbFilter;
|
2019-05-14 14:08:05 +02:00
|
|
|
public ImageLocation mediaLocation;
|
2019-03-03 21:40:48 +01:00
|
|
|
public String mediaFilter;
|
2019-05-14 14:08:05 +02:00
|
|
|
public Drawable thumb;
|
2022-06-21 04:51:00 +02:00
|
|
|
public long 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;
|
2019-12-31 14:08:08 +01:00
|
|
|
|
|
|
|
private boolean isSet() {
|
|
|
|
return imageLocation != null || thumbLocation != null || mediaLocation != null || thumb != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isWebfileSet() {
|
|
|
|
return imageLocation != null && (imageLocation.webFile != null || imageLocation.path != null) ||
|
|
|
|
thumbLocation != null && (thumbLocation.webFile != null || thumbLocation.path != null) ||
|
|
|
|
mediaLocation != null && (mediaLocation.webFile != null || mediaLocation.path != null);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void clear() {
|
|
|
|
imageLocation = null;
|
|
|
|
thumbLocation = null;
|
|
|
|
mediaLocation = null;
|
|
|
|
thumb = null;
|
|
|
|
}
|
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;
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
public final static int DEFAULT_CROSSFADE_DURATION = 150;
|
|
|
|
|
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;
|
2022-09-16 20:48:21 +02:00
|
|
|
private long currentTime;
|
|
|
|
private int fileLoadingPriority = FileLoader.PRIORITY_NORMAL;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
2019-07-18 15:01:39 +02:00
|
|
|
private int currentLayerNum;
|
2022-12-30 13:32:20 +01:00
|
|
|
public boolean ignoreNotifications;
|
2019-07-18 15:01:39 +02:00
|
|
|
private int currentOpenedLayerFlags;
|
2022-11-05 13:34:47 +01:00
|
|
|
private int isLastFrame;
|
2019-07-18 15:01:39 +02:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
private SetImageBackup setImageBackup;
|
|
|
|
|
2021-06-25 02:43:10 +02:00
|
|
|
private Object blendMode;
|
|
|
|
|
|
|
|
private Bitmap gradientBitmap;
|
|
|
|
private BitmapShader gradientShader;
|
|
|
|
private ComposeShader composeShader;
|
|
|
|
private Bitmap legacyBitmap;
|
|
|
|
private BitmapShader legacyShader;
|
|
|
|
private Canvas legacyCanvas;
|
|
|
|
private Paint legacyPaint;
|
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
private ImageLocation strippedLocation;
|
2019-05-14 14:08:05 +02:00
|
|
|
private ImageLocation currentImageLocation;
|
2019-03-03 21:40:48 +01:00
|
|
|
private String currentImageFilter;
|
2019-05-14 14:08:05 +02:00
|
|
|
private String currentImageKey;
|
2019-03-03 21:40:48 +01:00
|
|
|
private int imageTag;
|
|
|
|
private Drawable currentImageDrawable;
|
|
|
|
private BitmapShader imageShader;
|
2022-08-12 17:23:51 +02:00
|
|
|
protected int imageOrientation;
|
2019-03-03 21:40:48 +01:00
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
private ImageLocation currentThumbLocation;
|
2015-02-01 19:51:02 +01:00
|
|
|
private String currentThumbFilter;
|
2019-05-14 14:08:05 +02:00
|
|
|
private String currentThumbKey;
|
2019-03-03 21:40:48 +01:00
|
|
|
private int thumbTag;
|
|
|
|
private Drawable currentThumbDrawable;
|
2022-12-06 20:13:44 +01:00
|
|
|
public BitmapShader thumbShader;
|
2019-03-03 21:40:48 +01:00
|
|
|
private int thumbOrientation;
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
private ImageLocation currentMediaLocation;
|
2019-03-03 21:40:48 +01:00
|
|
|
private String currentMediaFilter;
|
2019-05-14 14:08:05 +02:00
|
|
|
private String currentMediaKey;
|
2019-03-03 21:40:48 +01:00
|
|
|
private int mediaTag;
|
|
|
|
private Drawable currentMediaDrawable;
|
|
|
|
private BitmapShader mediaShader;
|
|
|
|
|
2022-02-03 23:18:58 +01:00
|
|
|
private boolean useRoundForThumb = true;
|
2021-04-17 01:59:59 +02:00
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
private Drawable staticThumbDrawable;
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
private String currentExt;
|
2019-03-03 21:40:48 +01:00
|
|
|
|
2020-01-03 16:45:22 +01:00
|
|
|
private boolean ignoreImageSet;
|
|
|
|
|
2019-07-18 15:01:39 +02:00
|
|
|
private int currentGuid;
|
|
|
|
|
2022-06-21 04:51:00 +02:00
|
|
|
private long currentSize;
|
2017-07-23 14:56:38 +02:00
|
|
|
private int currentCacheType;
|
2022-08-12 17:23:51 +02:00
|
|
|
private boolean allowLottieVibration = true;
|
2016-01-11 18:19:48 +01:00
|
|
|
private boolean allowStartAnimation = true;
|
2020-06-04 18:47:15 +02:00
|
|
|
private boolean allowStartLottieAnimation = true;
|
2019-05-14 14:08:05 +02:00
|
|
|
private boolean useSharedAnimationQueue;
|
2017-07-08 18:32:04 +02:00
|
|
|
private boolean allowDecodeSingleFrame;
|
2019-08-22 01:53:26 +02:00
|
|
|
private int autoRepeat = 1;
|
2022-09-16 20:48:21 +02:00
|
|
|
private int autoRepeatCount = -1;
|
2022-08-12 17:23:51 +02:00
|
|
|
private long autoRepeatTimeout;
|
2019-08-22 01:53:26 +02:00
|
|
|
private boolean animationReadySent;
|
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
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
private float imageX, imageY, imageW, imageH;
|
2019-05-14 14:08:05 +02:00
|
|
|
private float sideClip;
|
|
|
|
private RectF drawRegion = new RectF();
|
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;
|
2020-01-23 07:15:40 +01:00
|
|
|
private int[] roundRadius = new int[4];
|
2021-11-05 11:06:49 +01:00
|
|
|
private boolean isRoundRect = true;
|
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();
|
2020-01-23 07:15:40 +01:00
|
|
|
private Path roundPath = new Path();
|
|
|
|
private static float[] radii = new float[8];
|
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;
|
2022-01-10 03:27:47 +01:00
|
|
|
private float previousAlpha = 1f;
|
2015-05-03 13:48:36 +02:00
|
|
|
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;
|
2022-11-06 02:16:18 +01:00
|
|
|
private float crossfadeByScale = .05f;
|
2015-05-03 13:48:36 +02:00
|
|
|
private ColorFilter colorFilter;
|
2019-12-31 14:08:08 +01:00
|
|
|
private boolean isRoundVideo;
|
2020-06-04 18:47:15 +02:00
|
|
|
private long startTime;
|
|
|
|
private long endTime;
|
|
|
|
private int crossfadeDuration = DEFAULT_CROSSFADE_DURATION;
|
|
|
|
private float pressedProgress;
|
|
|
|
private int animateFromIsPressed;
|
2021-09-20 07:54:41 +02:00
|
|
|
private String uniqKeyPrefix;
|
2021-11-05 11:06:49 +01:00
|
|
|
private ArrayList<Runnable> loadingOperations = new ArrayList<>();
|
2022-02-03 23:18:58 +01:00
|
|
|
private boolean attachedToWindow;
|
2022-06-21 04:51:00 +02:00
|
|
|
private boolean videoThumbIsSame;
|
2022-07-04 13:54:30 +02:00
|
|
|
private boolean allowLoadingOnAttachedOnly;
|
|
|
|
private boolean shouldLoadOnAttach;
|
2022-08-12 17:23:51 +02:00
|
|
|
private boolean skipUpdateFrame;
|
|
|
|
public boolean clip = true;
|
2022-06-21 04:51:00 +02:00
|
|
|
|
|
|
|
public int animatedFileDrawableRepeatMaxCount;
|
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-06-04 12:14:50 +02:00
|
|
|
public void setStrippedLocation(ImageLocation location) {
|
|
|
|
strippedLocation = location;
|
|
|
|
}
|
|
|
|
|
2020-01-03 16:45:22 +01:00
|
|
|
public void setIgnoreImageSet(boolean value) {
|
|
|
|
ignoreImageSet = value;
|
|
|
|
}
|
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
public ImageLocation getStrippedLocation() {
|
|
|
|
return strippedLocation;
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
public void setImage(ImageLocation imageLocation, String imageFilter, Drawable thumb, String ext, Object parentObject, int cacheType) {
|
|
|
|
setImage(imageLocation, imageFilter, null, null, thumb, 0, ext, parentObject, cacheType);
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
|
2022-06-21 04:51:00 +02:00
|
|
|
public void setImage(ImageLocation imageLocation, String imageFilter, Drawable thumb, long size, String ext, Object parentObject, int cacheType) {
|
2019-05-14 14:08:05 +02:00
|
|
|
setImage(imageLocation, imageFilter, null, null, thumb, size, ext, parentObject, cacheType);
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
|
2022-06-21 04:51:00 +02:00
|
|
|
public void setImage(String imagePath, String imageFilter, Drawable thumb, String ext, long size) {
|
2019-05-14 14:08:05 +02:00
|
|
|
setImage(ImageLocation.getForPath(imagePath), imageFilter, null, null, thumb, size, ext, null, 1);
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
public void setImage(ImageLocation imageLocation, String imageFilter, ImageLocation thumbLocation, String thumbFilter, String ext, Object parentObject, int cacheType) {
|
|
|
|
setImage(imageLocation, imageFilter, thumbLocation, thumbFilter, null, 0, ext, parentObject, cacheType);
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
2022-06-21 04:51:00 +02:00
|
|
|
public void setImage(ImageLocation imageLocation, String imageFilter, ImageLocation thumbLocation, String thumbFilter, long size, String ext, Object parentObject, int cacheType) {
|
2019-05-14 14:08:05 +02:00
|
|
|
setImage(imageLocation, imageFilter, thumbLocation, thumbFilter, null, size, ext, parentObject, cacheType);
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
2021-04-17 01:59:59 +02:00
|
|
|
public void setForUserOrChat(TLObject object, Drawable avatarDrawable) {
|
|
|
|
setForUserOrChat(object, avatarDrawable, null);
|
|
|
|
}
|
|
|
|
public void setForUserOrChat(TLObject object, Drawable avatarDrawable, Object parentObject) {
|
2022-06-21 04:51:00 +02:00
|
|
|
setForUserOrChat(object, avatarDrawable, null, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setForUserOrChat(TLObject object, Drawable avatarDrawable, Object parentObject, boolean animationEnabled) {
|
2021-04-17 01:59:59 +02:00
|
|
|
if (parentObject == null) {
|
|
|
|
parentObject = object;
|
|
|
|
}
|
|
|
|
setUseRoundForThumbDrawable(true);
|
|
|
|
BitmapDrawable strippedBitmap = null;
|
|
|
|
boolean hasStripped = false;
|
2022-06-21 04:51:00 +02:00
|
|
|
ImageLocation videoLocation = null;
|
2021-04-17 01:59:59 +02:00
|
|
|
if (object instanceof TLRPC.User) {
|
|
|
|
TLRPC.User user = (TLRPC.User) object;
|
|
|
|
if (user.photo != null) {
|
|
|
|
strippedBitmap = user.photo.strippedBitmap;
|
|
|
|
hasStripped = user.photo.stripped_thumb != null;
|
2022-12-30 13:32:20 +01:00
|
|
|
if (animationEnabled && MessagesController.getInstance(currentAccount).isPremiumUser(user) && user.photo.has_video && !SharedConfig.getLiteMode().enabled()) {
|
2022-06-21 04:51:00 +02:00
|
|
|
final TLRPC.UserFull userFull = MessagesController.getInstance(currentAccount).getUserFull(user.id);
|
|
|
|
if (userFull == null) {
|
|
|
|
MessagesController.getInstance(currentAccount).loadFullUser(user, currentGuid, false);
|
2022-06-28 12:00:33 +02:00
|
|
|
} else {
|
2022-12-06 20:13:44 +01:00
|
|
|
TLRPC.Photo photo = userFull.profile_photo;
|
|
|
|
if (photo != null) {
|
|
|
|
ArrayList<TLRPC.VideoSize> videoSizes = photo.video_sizes;
|
|
|
|
if (videoSizes != null && !videoSizes.isEmpty()) {
|
|
|
|
TLRPC.VideoSize videoSize = videoSizes.get(0);
|
|
|
|
for (int i = 0; i < videoSizes.size(); i++) {
|
|
|
|
TLRPC.VideoSize videoSize1 = videoSizes.get(i);
|
|
|
|
if ("p".equals(videoSize1.type)) {
|
|
|
|
videoSize = videoSize1;
|
2022-11-12 09:41:35 +01:00
|
|
|
break;
|
|
|
|
}
|
2022-06-28 12:00:33 +02:00
|
|
|
}
|
2022-11-12 09:41:35 +01:00
|
|
|
videoLocation = ImageLocation.getForPhoto(videoSize, photo);
|
2022-06-21 04:51:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-17 01:59:59 +02:00
|
|
|
}
|
|
|
|
} else if (object instanceof TLRPC.Chat) {
|
|
|
|
TLRPC.Chat chat = (TLRPC.Chat) object;
|
|
|
|
if (chat.photo != null) {
|
|
|
|
strippedBitmap = chat.photo.strippedBitmap;
|
|
|
|
hasStripped = chat.photo.stripped_thumb != null;
|
|
|
|
}
|
|
|
|
}
|
2022-06-21 04:51:00 +02:00
|
|
|
ImageLocation location = ImageLocation.getForUserOrChat(object, ImageLocation.TYPE_SMALL);
|
|
|
|
String filter = "50_50";
|
|
|
|
if (videoLocation != null) {
|
2022-12-30 13:32:20 +01:00
|
|
|
setImage(videoLocation, "avatar", location, filter, null, null, strippedBitmap, 0, null, parentObject, 0);
|
2022-06-21 04:51:00 +02:00
|
|
|
animatedFileDrawableRepeatMaxCount = 3;
|
2021-04-17 01:59:59 +02:00
|
|
|
} else {
|
2022-06-21 04:51:00 +02:00
|
|
|
if (strippedBitmap != null) {
|
|
|
|
setImage(location, filter, strippedBitmap, null, parentObject, 0);
|
|
|
|
} else if (hasStripped) {
|
|
|
|
setImage(location, filter, ImageLocation.getForUserOrChat(object, ImageLocation.TYPE_STRIPPED), "50_50_b", avatarDrawable, parentObject, 0);
|
|
|
|
} else {
|
|
|
|
setImage(location, filter, avatarDrawable, null, parentObject, 0);
|
|
|
|
}
|
2021-04-17 01:59:59 +02:00
|
|
|
}
|
2022-06-21 04:51:00 +02:00
|
|
|
|
2021-04-17 01:59:59 +02:00
|
|
|
}
|
|
|
|
|
2021-04-14 03:44:46 +02:00
|
|
|
public void setImage(ImageLocation fileLocation, String fileFilter, ImageLocation thumbLocation, String thumbFilter, Drawable thumb, Object parentObject, int cacheType) {
|
|
|
|
setImage(null, null, fileLocation, fileFilter, thumbLocation, thumbFilter, thumb, 0, null, parentObject, cacheType);
|
|
|
|
}
|
|
|
|
|
2022-06-21 04:51:00 +02:00
|
|
|
public void setImage(ImageLocation fileLocation, String fileFilter, ImageLocation thumbLocation, String thumbFilter, Drawable thumb, long size, String ext, Object parentObject, int cacheType) {
|
2019-05-14 14:08:05 +02:00
|
|
|
setImage(null, null, fileLocation, fileFilter, thumbLocation, thumbFilter, thumb, size, ext, parentObject, cacheType);
|
2019-03-03 21:40:48 +01:00
|
|
|
}
|
|
|
|
|
2022-06-21 04:51:00 +02:00
|
|
|
public void setImage(ImageLocation mediaLocation, String mediaFilter, ImageLocation imageLocation, String imageFilter, ImageLocation thumbLocation, String thumbFilter, Drawable thumb, long size, String ext, Object parentObject, int cacheType) {
|
2022-07-04 13:54:30 +02:00
|
|
|
if (allowLoadingOnAttachedOnly && !attachedToWindow) {
|
|
|
|
if (setImageBackup == null) {
|
|
|
|
setImageBackup = new SetImageBackup();
|
|
|
|
}
|
|
|
|
setImageBackup.mediaLocation = mediaLocation;
|
|
|
|
setImageBackup.mediaFilter = mediaFilter;
|
|
|
|
setImageBackup.imageLocation = imageLocation;
|
|
|
|
setImageBackup.imageFilter = imageFilter;
|
|
|
|
setImageBackup.thumbLocation = thumbLocation;
|
|
|
|
setImageBackup.thumbFilter = thumbFilter;
|
|
|
|
setImageBackup.thumb = thumb;
|
|
|
|
setImageBackup.size = size;
|
|
|
|
setImageBackup.ext = ext;
|
|
|
|
setImageBackup.cacheType = cacheType;
|
|
|
|
setImageBackup.parentObject = parentObject;
|
|
|
|
return;
|
|
|
|
}
|
2020-01-03 16:45:22 +01:00
|
|
|
if (ignoreImageSet) {
|
|
|
|
return;
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
if (crossfadeWithOldImage && setImageBackup != null && setImageBackup.isWebfileSet()) {
|
|
|
|
setBackupImage();
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
if (setImageBackup != null) {
|
2019-12-31 14:08:08 +01:00
|
|
|
setImageBackup.clear();
|
2019-03-03 21:40:48 +01:00
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
if (imageLocation == null && thumbLocation == null && mediaLocation == null) {
|
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
|
|
|
currentImageLocation = null;
|
|
|
|
currentImageFilter = null;
|
2019-05-14 14:08:05 +02:00
|
|
|
currentImageKey = null;
|
2019-03-03 21:40:48 +01:00
|
|
|
currentMediaLocation = null;
|
|
|
|
currentMediaFilter = null;
|
2019-05-14 14:08:05 +02:00
|
|
|
currentMediaKey = null;
|
2019-03-03 21:40:48 +01:00
|
|
|
currentThumbLocation = null;
|
2015-02-01 19:51:02 +01:00
|
|
|
currentThumbFilter = null;
|
2019-05-14 14:08:05 +02:00
|
|
|
currentThumbKey = null;
|
2019-03-03 21:40:48 +01:00
|
|
|
|
|
|
|
currentMediaDrawable = null;
|
|
|
|
mediaShader = null;
|
|
|
|
currentImageDrawable = null;
|
|
|
|
imageShader = null;
|
2021-06-25 02:43:10 +02:00
|
|
|
composeShader = null;
|
2019-03-03 21:40:48 +01:00
|
|
|
thumbShader = null;
|
|
|
|
crossfadeShader = null;
|
2021-06-25 02:43:10 +02:00
|
|
|
legacyShader = null;
|
|
|
|
legacyCanvas = null;
|
|
|
|
if (legacyBitmap != null) {
|
|
|
|
legacyBitmap.recycle();
|
|
|
|
legacyBitmap = null;
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
|
|
|
|
currentExt = ext;
|
2019-01-23 18:03:33 +01:00
|
|
|
currentParentObject = null;
|
2017-07-23 14:56:38 +02:00
|
|
|
currentCacheType = 0;
|
2022-02-12 06:22:45 +01:00
|
|
|
roundPaint.setShader(null);
|
2019-03-03 21:40:48 +01:00
|
|
|
staticThumbDrawable = thumb;
|
|
|
|
currentAlpha = 1.0f;
|
2022-02-01 14:00:45 +01:00
|
|
|
previousAlpha = 1f;
|
2015-02-01 19:51:02 +01:00
|
|
|
currentSize = 0;
|
2019-03-03 21:40:48 +01:00
|
|
|
|
2020-12-23 08:48:30 +01:00
|
|
|
if (staticThumbDrawable instanceof SvgHelper.SvgDrawable) {
|
|
|
|
((SvgHelper.SvgDrawable) staticThumbDrawable).setParent(this);
|
|
|
|
}
|
2022-11-05 13:34:47 +01:00
|
|
|
updateDrawableRadius(staticThumbDrawable);
|
2020-12-23 08:48:30 +01:00
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
ImageLoader.getInstance().cancelLoadingForImageReceiver(this, true);
|
2022-08-12 17:23:51 +02:00
|
|
|
invalidate();
|
2015-02-01 19:51:02 +01:00
|
|
|
if (delegate != null) {
|
2020-03-30 14:00:09 +02:00
|
|
|
delegate.didSetImage(this, currentImageDrawable != null || currentThumbDrawable != null || staticThumbDrawable != null || currentMediaDrawable != null, currentImageDrawable == null && currentMediaDrawable == null, false);
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
String imageKey = imageLocation != null ? imageLocation.getKey(parentObject, null, false) : null;
|
2019-05-14 14:08:05 +02:00
|
|
|
if (imageKey == null && imageLocation != null) {
|
|
|
|
imageLocation = null;
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
2022-09-16 20:48:21 +02:00
|
|
|
animatedFileDrawableRepeatMaxCount = Math.max(autoRepeatCount, 0);
|
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;
|
|
|
|
}
|
|
|
|
|
2021-09-20 07:54:41 +02:00
|
|
|
if (uniqKeyPrefix != null) {
|
|
|
|
imageKey = uniqKeyPrefix + imageKey;
|
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
String mediaKey = mediaLocation != null ? mediaLocation.getKey(parentObject, null, false) : null;
|
2019-03-03 21:40:48 +01:00
|
|
|
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
|
|
|
|
2022-08-12 17:23:51 +02:00
|
|
|
if (uniqKeyPrefix != null) {
|
|
|
|
mediaKey = uniqKeyPrefix + mediaKey;
|
|
|
|
}
|
|
|
|
|
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) {
|
2020-03-30 14:00:09 +02:00
|
|
|
delegate.didSetImage(this, currentImageDrawable != null || currentThumbDrawable != null || staticThumbDrawable != null || currentMediaDrawable != null, currentImageDrawable == null && currentMediaDrawable == null, false);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2020-06-04 18:47:15 +02:00
|
|
|
if (!canceledLoading) {
|
2015-02-01 19:51:02 +01:00
|
|
|
return;
|
2014-10-18 01:06:51 +02:00
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
ImageLocation strippedLoc;
|
|
|
|
if (strippedLocation != null) {
|
|
|
|
strippedLoc = strippedLocation;
|
|
|
|
} else {
|
|
|
|
strippedLoc = mediaLocation != null ? mediaLocation : imageLocation;
|
|
|
|
}
|
2021-04-09 15:17:32 +02:00
|
|
|
if (strippedLoc == null) {
|
|
|
|
strippedLoc = thumbLocation;
|
|
|
|
}
|
2019-06-04 12:14:50 +02:00
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
String thumbKey = thumbLocation != null ? thumbLocation.getKey(parentObject, strippedLoc, false) : null;
|
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) {
|
2022-11-06 02:16:18 +01:00
|
|
|
if (currentParentObject instanceof MessageObject && ((MessageObject) currentParentObject).lastGeoWebFileSet != null && MessageObject.getMedia((MessageObject) currentParentObject) instanceof TLRPC.TL_messageMediaGeoLive) {
|
|
|
|
((MessageObject) currentParentObject).lastGeoWebFileLoaded = ((MessageObject) currentParentObject).lastGeoWebFileSet;
|
|
|
|
}
|
2020-06-04 18:47:15 +02:00
|
|
|
if (currentMediaDrawable != null) {
|
|
|
|
if (currentMediaDrawable instanceof AnimatedFileDrawable) {
|
|
|
|
((AnimatedFileDrawable) currentMediaDrawable).stop();
|
2022-06-21 04:51:00 +02:00
|
|
|
((AnimatedFileDrawable) currentMediaDrawable).removeParent(this);
|
2020-06-04 18:47:15 +02:00
|
|
|
}
|
|
|
|
recycleBitmap(thumbKey, TYPE_THUMB);
|
|
|
|
recycleBitmap(null, TYPE_CROSSFDADE);
|
|
|
|
recycleBitmap(mediaKey, TYPE_IMAGE);
|
|
|
|
crossfadeImage = currentMediaDrawable;
|
|
|
|
crossfadeShader = mediaShader;
|
|
|
|
crossfadeKey = currentImageKey;
|
|
|
|
crossfadingWithThumb = false;
|
|
|
|
currentMediaDrawable = null;
|
|
|
|
currentMediaKey = null;
|
|
|
|
} else if (currentImageDrawable != null) {
|
2019-03-03 21:40:48 +01:00
|
|
|
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
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
currentImageLocation = imageLocation;
|
2019-03-03 21:40:48 +01:00
|
|
|
currentImageFilter = imageFilter;
|
2019-05-14 14:08:05 +02:00
|
|
|
currentImageKey = imageKey;
|
2019-03-03 21:40:48 +01:00
|
|
|
currentMediaLocation = mediaLocation;
|
|
|
|
currentMediaFilter = mediaFilter;
|
2019-05-14 14:08:05 +02:00
|
|
|
currentMediaKey = mediaKey;
|
2019-03-03 21:40:48 +01:00
|
|
|
currentThumbLocation = thumbLocation;
|
2015-02-01 19:51:02 +01:00
|
|
|
currentThumbFilter = thumbFilter;
|
2019-05-14 14:08:05 +02:00
|
|
|
currentThumbKey = thumbKey;
|
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;
|
2021-06-25 02:43:10 +02:00
|
|
|
composeShader = null;
|
2019-03-03 21:40:48 +01:00
|
|
|
thumbShader = null;
|
|
|
|
mediaShader = null;
|
2021-06-25 02:43:10 +02:00
|
|
|
legacyShader = null;
|
|
|
|
legacyCanvas = null;
|
2022-02-12 06:22:45 +01:00
|
|
|
roundPaint.setShader(null);
|
2021-06-25 02:43:10 +02:00
|
|
|
if (legacyBitmap != null) {
|
|
|
|
legacyBitmap.recycle();
|
|
|
|
legacyBitmap = null;
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
currentAlpha = 1.0f;
|
2022-01-10 03:27:47 +01:00
|
|
|
previousAlpha = 1f;
|
2015-02-01 19:51:02 +01:00
|
|
|
|
2022-11-06 02:16:18 +01:00
|
|
|
if (staticThumbDrawable instanceof ClipRoundedDrawable) {
|
|
|
|
if (((ClipRoundedDrawable) staticThumbDrawable).getDrawable() instanceof SvgHelper.SvgDrawable) {
|
|
|
|
((SvgHelper.SvgDrawable) ((ClipRoundedDrawable) staticThumbDrawable).getDrawable()).setParent(this);
|
|
|
|
}
|
|
|
|
} else if (staticThumbDrawable instanceof SvgHelper.SvgDrawable) {
|
2020-12-23 08:48:30 +01:00
|
|
|
((SvgHelper.SvgDrawable) staticThumbDrawable).setParent(this);
|
|
|
|
}
|
2022-03-11 17:49:54 +01:00
|
|
|
updateDrawableRadius(staticThumbDrawable);
|
2020-12-23 08:48:30 +01:00
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
if (delegate != null) {
|
2020-03-30 14:00:09 +02:00
|
|
|
delegate.didSetImage(this, currentImageDrawable != null || currentThumbDrawable != null || staticThumbDrawable != null || currentMediaDrawable != null, currentImageDrawable == null && currentMediaDrawable == null, false);
|
2014-10-21 22:35:16 +02:00
|
|
|
}
|
2022-07-04 13:54:30 +02:00
|
|
|
loadImage();
|
|
|
|
isRoundVideo = parentObject instanceof MessageObject && ((MessageObject) parentObject).isRoundVideo();
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
|
2022-07-04 13:54:30 +02:00
|
|
|
private void loadImage() {
|
2015-02-01 19:51:02 +01:00
|
|
|
ImageLoader.getInstance().loadImageForImageReceiver(this);
|
2022-08-12 17:23:51 +02:00
|
|
|
invalidate();
|
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
|
|
|
}
|
|
|
|
|
2019-07-18 15:01:39 +02:00
|
|
|
public void setLayerNum(int value) {
|
|
|
|
currentLayerNum = value;
|
2022-09-21 16:20:30 +02:00
|
|
|
if (attachedToWindow) {
|
|
|
|
currentOpenedLayerFlags = NotificationCenter.getGlobalInstance().getCurrentHeavyOperationFlags();
|
|
|
|
currentOpenedLayerFlags &= ~currentLayerNum;
|
|
|
|
}
|
2019-07-18 15:01:39 +02: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);
|
2022-02-03 23:18:58 +01:00
|
|
|
if (attachedToWindow) {
|
2022-06-21 04:51:00 +02:00
|
|
|
fileDrawable.addParent(this);
|
2022-02-03 23:18:58 +01:00
|
|
|
}
|
2022-02-01 14:00:45 +01:00
|
|
|
fileDrawable.setUseSharedQueue(useSharedAnimationQueue || fileDrawable.isWebmSticker);
|
2021-06-25 02:43:10 +02:00
|
|
|
if (allowStartAnimation && currentOpenedLayerFlags == 0) {
|
2022-06-21 04:51:00 +02:00
|
|
|
fileDrawable.checkRepeat();
|
2019-03-03 21:40:48 +01:00
|
|
|
}
|
|
|
|
fileDrawable.setAllowDecodeSingleFrame(allowDecodeSingleFrame);
|
2019-07-18 15:01:39 +02:00
|
|
|
} else if (bitmap instanceof RLottieDrawable) {
|
|
|
|
RLottieDrawable fileDrawable = (RLottieDrawable) bitmap;
|
2022-08-12 17:23:51 +02:00
|
|
|
if (attachedToWindow) {
|
|
|
|
fileDrawable.addParentView(this);
|
|
|
|
}
|
|
|
|
if (fileDrawable != null) {
|
|
|
|
fileDrawable.setAllowVibration(allowLottieVibration);
|
|
|
|
}
|
2020-10-30 11:26:29 +01:00
|
|
|
if (allowStartLottieAnimation && (!fileDrawable.isHeavyDrawable() || currentOpenedLayerFlags == 0)) {
|
2019-07-18 15:01:39 +02:00
|
|
|
fileDrawable.start();
|
|
|
|
}
|
|
|
|
fileDrawable.setAllowDecodeSingleFrame(true);
|
2019-03-03 21:40:48 +01:00
|
|
|
}
|
2022-02-01 14:00:45 +01:00
|
|
|
thumbShader = null;
|
2022-02-12 06:22:45 +01:00
|
|
|
roundPaint.setShader(null);
|
2019-03-03 21:40:48 +01:00
|
|
|
staticThumbDrawable = bitmap;
|
2019-12-31 14:08:08 +01:00
|
|
|
updateDrawableRadius(bitmap);
|
2019-03-03 21:40:48 +01:00
|
|
|
currentMediaLocation = null;
|
2019-05-14 14:08:05 +02:00
|
|
|
currentMediaFilter = null;
|
2022-06-21 04:51:00 +02:00
|
|
|
if (currentMediaDrawable instanceof AnimatedFileDrawable) {
|
|
|
|
((AnimatedFileDrawable) currentMediaDrawable).removeParent(this);
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
currentMediaDrawable = null;
|
|
|
|
currentMediaKey = null;
|
|
|
|
mediaShader = null;
|
|
|
|
|
|
|
|
currentImageLocation = null;
|
2019-05-14 14:08:05 +02:00
|
|
|
currentImageFilter = null;
|
2019-03-03 21:40:48 +01:00
|
|
|
currentImageDrawable = null;
|
|
|
|
currentImageKey = null;
|
|
|
|
imageShader = null;
|
2021-06-25 02:43:10 +02:00
|
|
|
composeShader = null;
|
|
|
|
legacyShader = null;
|
|
|
|
legacyCanvas = null;
|
|
|
|
if (legacyBitmap != null) {
|
|
|
|
legacyBitmap.recycle();
|
|
|
|
legacyBitmap = null;
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
currentThumbLocation = null;
|
|
|
|
currentThumbFilter = null;
|
2019-05-14 14:08:05 +02:00
|
|
|
currentThumbKey = 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;
|
2022-01-10 03:27:47 +01:00
|
|
|
previousAlpha = 1f;
|
2019-03-03 21:40:48 +01:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
if (setImageBackup != null) {
|
2019-12-31 14:08:08 +01:00
|
|
|
setImageBackup.clear();
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
if (delegate != null) {
|
2020-03-30 14:00:09 +02:00
|
|
|
delegate.didSetImage(this, currentThumbDrawable != null || staticThumbDrawable != null, true, false);
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
2022-08-12 17:23:51 +02:00
|
|
|
invalidate();
|
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
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
private void setDrawableShader(Drawable drawable, BitmapShader shader) {
|
|
|
|
if (drawable == currentThumbDrawable || drawable == staticThumbDrawable) {
|
|
|
|
thumbShader = shader;
|
|
|
|
} else if (drawable == currentMediaDrawable) {
|
|
|
|
mediaShader = shader;
|
|
|
|
} else if (drawable == currentImageDrawable) {
|
|
|
|
imageShader = shader;
|
2021-06-25 02:43:10 +02:00
|
|
|
if (gradientShader != null && drawable instanceof BitmapDrawable) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 28) {
|
|
|
|
composeShader = new ComposeShader(gradientShader, imageShader, PorterDuff.Mode.DST_IN);
|
|
|
|
} else {
|
|
|
|
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
|
|
|
|
int w = bitmapDrawable.getBitmap().getWidth();
|
|
|
|
int h = bitmapDrawable.getBitmap().getHeight();
|
|
|
|
if (legacyBitmap == null || legacyBitmap.getWidth() != w || legacyBitmap.getHeight() != h) {
|
|
|
|
if (legacyBitmap != null) {
|
|
|
|
legacyBitmap.recycle();
|
|
|
|
}
|
|
|
|
legacyBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
|
|
|
|
legacyCanvas = new Canvas(legacyBitmap);
|
|
|
|
legacyShader = new BitmapShader(legacyBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
|
|
|
|
if (legacyPaint == null) {
|
|
|
|
legacyPaint = new Paint();
|
|
|
|
legacyPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-23 07:15:40 +01:00
|
|
|
private boolean hasRoundRadius() {
|
|
|
|
/*for (int a = 0; a < roundRadius.length; a++) {
|
|
|
|
if (roundRadius[a] != 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
private void updateDrawableRadius(Drawable drawable) {
|
2022-02-01 14:00:45 +01:00
|
|
|
if (drawable == null) {
|
|
|
|
return;
|
|
|
|
}
|
2022-11-06 02:16:18 +01:00
|
|
|
if (drawable instanceof ClipRoundedDrawable) {
|
|
|
|
((ClipRoundedDrawable) drawable).setRadii(roundRadius[0], roundRadius[1], roundRadius[2], roundRadius[3]);
|
|
|
|
} else if ((hasRoundRadius() || gradientShader != null) && (drawable instanceof BitmapDrawable || drawable instanceof AvatarDrawable)) {
|
2022-11-05 13:34:47 +01:00
|
|
|
if (drawable instanceof AvatarDrawable) {
|
|
|
|
((AvatarDrawable) drawable).setRoundRadius(roundRadius[0]);
|
|
|
|
} else {
|
|
|
|
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
|
|
|
|
if (bitmapDrawable instanceof RLottieDrawable) {
|
|
|
|
|
|
|
|
} else if (bitmapDrawable instanceof AnimatedFileDrawable) {
|
|
|
|
AnimatedFileDrawable animatedFileDrawable = (AnimatedFileDrawable) drawable;
|
|
|
|
animatedFileDrawable.setRoundRadius(roundRadius);
|
|
|
|
} else if (bitmapDrawable.getBitmap() != null) {
|
|
|
|
setDrawableShader(drawable, new BitmapShader(bitmapDrawable.getBitmap(), Shader.TileMode.REPEAT, Shader.TileMode.REPEAT));
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
setDrawableShader(drawable, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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() {
|
2022-02-03 23:18:58 +01:00
|
|
|
attachedToWindow = false;
|
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;
|
2019-05-14 14:08:05 +02:00
|
|
|
setImageBackup.imageLocation = currentImageLocation;
|
|
|
|
setImageBackup.imageFilter = currentImageFilter;
|
2015-05-03 13:48:36 +02:00
|
|
|
setImageBackup.thumbLocation = currentThumbLocation;
|
|
|
|
setImageBackup.thumbFilter = currentThumbFilter;
|
2019-05-14 14:08:05 +02:00
|
|
|
setImageBackup.thumb = staticThumbDrawable;
|
2015-05-03 13:48:36 +02:00
|
|
|
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
|
|
|
}
|
2022-12-30 13:32:20 +01:00
|
|
|
if (!ignoreNotifications) {
|
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didReplacedPhotoInMemCache);
|
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.stopAllHeavyOperations);
|
|
|
|
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.startAllHeavyOperations);
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
if (staticThumbDrawable != null) {
|
|
|
|
staticThumbDrawable = null;
|
|
|
|
thumbShader = null;
|
2022-02-12 06:22:45 +01:00
|
|
|
roundPaint.setShader(null);
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
clearImage();
|
2020-06-04 18:47:15 +02:00
|
|
|
if (isPressed == 0) {
|
|
|
|
pressedProgress = 0f;
|
|
|
|
}
|
2022-02-03 23:18:58 +01:00
|
|
|
|
|
|
|
AnimatedFileDrawable animatedFileDrawable = getAnimation();
|
|
|
|
if (animatedFileDrawable != null) {
|
2022-06-21 04:51:00 +02:00
|
|
|
animatedFileDrawable.removeParent(this);
|
2022-02-03 23:18:58 +01:00
|
|
|
}
|
2022-08-12 17:23:51 +02:00
|
|
|
RLottieDrawable lottieDrawable = getLottieAnimation();
|
|
|
|
if (lottieDrawable != null) {
|
|
|
|
lottieDrawable.removeParentView(this);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
2022-09-16 20:48:21 +02:00
|
|
|
public boolean setBackupImage() {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (setImageBackup != null && setImageBackup.isSet()) {
|
|
|
|
SetImageBackup temp = setImageBackup;
|
|
|
|
setImageBackup = null;
|
|
|
|
setImage(temp.mediaLocation, temp.mediaFilter, temp.imageLocation, temp.imageFilter, temp.thumbLocation, temp.thumbFilter, temp.thumb, temp.size, temp.ext, temp.parentObject, temp.cacheType);
|
|
|
|
temp.clear();
|
|
|
|
setImageBackup = temp;
|
2020-10-30 11:26:29 +01:00
|
|
|
RLottieDrawable lottieDrawable = getLottieAnimation();
|
2022-08-12 17:23:51 +02:00
|
|
|
if (lottieDrawable != null) {
|
|
|
|
lottieDrawable.setAllowVibration(allowLottieVibration);
|
|
|
|
}
|
2020-10-30 11:26:29 +01:00
|
|
|
if (lottieDrawable != null && allowStartLottieAnimation && (!lottieDrawable.isHeavyDrawable() || currentOpenedLayerFlags == 0)) {
|
|
|
|
lottieDrawable.start();
|
2019-07-18 15:01:39 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
return true;
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-12-30 13:32:20 +01:00
|
|
|
private int bufferedFrame;
|
|
|
|
public void incrementFrames(int inc) {
|
|
|
|
if (currentMediaDrawable instanceof RLottieDrawable) {
|
|
|
|
// RLottieDrawable rlottie = (RLottieDrawable) currentMediaDrawable;
|
|
|
|
// inc = (int) Math.round((float) rlottie.getFramesCount() / rlottie.getDuration() * (1f / 30f));
|
|
|
|
// rlottie.setCurrentFrame(
|
|
|
|
// (rlottie.getCurrentFrame() + inc) % (int) rlottie.getFramesCount()
|
|
|
|
// );
|
|
|
|
} else if (currentMediaDrawable instanceof AnimatedFileDrawable) {
|
|
|
|
int lastFrame = (int) bufferedFrame;
|
|
|
|
bufferedFrame += inc;
|
|
|
|
int currentFrame = (int) bufferedFrame;
|
|
|
|
while (lastFrame != currentFrame) {
|
|
|
|
((AnimatedFileDrawable) currentMediaDrawable).getNextFrame();
|
|
|
|
currentFrame--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-31 14:08:08 +01:00
|
|
|
public boolean onAttachedToWindow() {
|
2022-02-03 23:18:58 +01:00
|
|
|
attachedToWindow = true;
|
2019-12-31 14:08:08 +01:00
|
|
|
currentOpenedLayerFlags = NotificationCenter.getGlobalInstance().getCurrentHeavyOperationFlags();
|
2021-04-17 01:59:59 +02:00
|
|
|
currentOpenedLayerFlags &= ~currentLayerNum;
|
2022-12-30 13:32:20 +01:00
|
|
|
if (!ignoreNotifications) {
|
|
|
|
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didReplacedPhotoInMemCache);
|
|
|
|
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.stopAllHeavyOperations);
|
|
|
|
NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.startAllHeavyOperations);
|
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
if (setBackupImage()) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-10-30 11:26:29 +01:00
|
|
|
RLottieDrawable lottieDrawable = getLottieAnimation();
|
2022-08-12 17:23:51 +02:00
|
|
|
if (lottieDrawable != null) {
|
|
|
|
lottieDrawable.addParentView(this);
|
|
|
|
lottieDrawable.setAllowVibration(allowLottieVibration);
|
|
|
|
}
|
2020-10-30 11:26:29 +01:00
|
|
|
if (lottieDrawable != null && allowStartLottieAnimation && (!lottieDrawable.isHeavyDrawable() || currentOpenedLayerFlags == 0)) {
|
|
|
|
lottieDrawable.start();
|
2019-07-18 15:01:39 +02:00
|
|
|
}
|
2021-06-25 02:43:10 +02:00
|
|
|
AnimatedFileDrawable animatedFileDrawable = getAnimation();
|
2022-08-12 17:23:51 +02:00
|
|
|
if (animatedFileDrawable != null) {
|
2022-06-21 04:51:00 +02:00
|
|
|
animatedFileDrawable.addParent(this);
|
2022-02-03 23:18:58 +01:00
|
|
|
}
|
2021-06-25 02:43:10 +02:00
|
|
|
if (animatedFileDrawable != null && allowStartAnimation && currentOpenedLayerFlags == 0) {
|
2022-06-21 04:51:00 +02:00
|
|
|
animatedFileDrawable.checkRepeat();
|
2022-08-12 17:23:51 +02:00
|
|
|
invalidate();
|
2021-06-25 02:43:10 +02:00
|
|
|
}
|
2020-09-30 15:48:47 +02:00
|
|
|
if (NotificationCenter.getGlobalInstance().isAnimationInProgress()) {
|
|
|
|
didReceivedNotification(NotificationCenter.stopAllHeavyOperations, currentAccount, 512);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-12 17:23:51 +02:00
|
|
|
private void drawDrawable(Canvas canvas, Drawable drawable, int alpha, BitmapShader shader, int orientation, BackgroundThreadDrawHolder backgroundThreadDrawHolder) {
|
2020-06-04 18:47:15 +02:00
|
|
|
if (isPressed == 0 && pressedProgress != 0) {
|
|
|
|
pressedProgress -= 16 / 150f;
|
|
|
|
if (pressedProgress < 0) {
|
|
|
|
pressedProgress = 0;
|
|
|
|
}
|
2022-08-12 17:23:51 +02:00
|
|
|
invalidate();
|
2020-06-04 18:47:15 +02:00
|
|
|
}
|
|
|
|
if (isPressed != 0) {
|
|
|
|
pressedProgress = 1f;
|
|
|
|
animateFromIsPressed = isPressed;
|
|
|
|
}
|
|
|
|
if (pressedProgress == 0 || pressedProgress == 1f) {
|
2022-08-12 17:23:51 +02:00
|
|
|
drawDrawable(canvas, drawable, alpha, shader, orientation, isPressed, backgroundThreadDrawHolder);
|
2020-06-04 18:47:15 +02:00
|
|
|
} else {
|
2022-08-12 17:23:51 +02:00
|
|
|
drawDrawable(canvas, drawable, alpha, shader, orientation, isPressed, backgroundThreadDrawHolder);
|
|
|
|
drawDrawable(canvas, drawable, (int) (alpha * pressedProgress), shader, orientation, animateFromIsPressed, backgroundThreadDrawHolder);
|
2020-06-04 18:47:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-17 01:59:59 +02:00
|
|
|
public void setUseRoundForThumbDrawable(boolean value) {
|
|
|
|
useRoundForThumb = value;
|
|
|
|
}
|
|
|
|
|
2022-08-12 17:23:51 +02:00
|
|
|
protected void drawDrawable(Canvas canvas, Drawable drawable, int alpha, BitmapShader shader, int orientation, int isPressed, BackgroundThreadDrawHolder backgroundThreadDrawHolder) {
|
|
|
|
float imageX, imageY, imageH, imageW;
|
|
|
|
RectF drawRegion;
|
2022-09-16 20:48:21 +02:00
|
|
|
ColorFilter colorFilter;
|
|
|
|
int[] roundRadius;
|
2022-11-05 13:34:47 +01:00
|
|
|
boolean reactionLastFrame = false;
|
2022-08-12 17:23:51 +02:00
|
|
|
if (backgroundThreadDrawHolder != null) {
|
|
|
|
imageX = backgroundThreadDrawHolder.imageX;
|
|
|
|
imageY = backgroundThreadDrawHolder.imageY;
|
|
|
|
imageH = backgroundThreadDrawHolder.imageH;
|
|
|
|
imageW = backgroundThreadDrawHolder.imageW;
|
|
|
|
drawRegion = backgroundThreadDrawHolder.drawRegion;
|
2022-09-16 20:48:21 +02:00
|
|
|
colorFilter = backgroundThreadDrawHolder.colorFilter;
|
|
|
|
roundRadius = backgroundThreadDrawHolder.roundRadius;
|
2022-08-12 17:23:51 +02:00
|
|
|
} else {
|
|
|
|
imageX = this.imageX;
|
|
|
|
imageY = this.imageY;
|
|
|
|
imageH = this.imageH;
|
|
|
|
imageW = this.imageW;
|
|
|
|
drawRegion = this.drawRegion;
|
2022-09-16 20:48:21 +02:00
|
|
|
colorFilter = this.colorFilter;
|
|
|
|
roundRadius = this.roundRadius;
|
2022-08-12 17:23:51 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
if (drawable instanceof BitmapDrawable) {
|
|
|
|
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
|
2022-08-12 17:23:51 +02:00
|
|
|
if (drawable instanceof RLottieDrawable) {
|
|
|
|
((RLottieDrawable) drawable).skipFrameUpdate = skipUpdateFrame;
|
|
|
|
} else if (drawable instanceof AnimatedFileDrawable) {
|
|
|
|
((AnimatedFileDrawable) drawable).skipFrameUpdate = skipUpdateFrame;
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
Paint paint;
|
|
|
|
if (shader != null) {
|
|
|
|
paint = roundPaint;
|
|
|
|
} else {
|
|
|
|
paint = bitmapDrawable.getPaint();
|
|
|
|
}
|
2021-06-25 02:43:10 +02:00
|
|
|
if (Build.VERSION.SDK_INT >= 29) {
|
|
|
|
if (blendMode != null && gradientShader == null) {
|
|
|
|
paint.setBlendMode((BlendMode) blendMode);
|
|
|
|
} else {
|
|
|
|
paint.setBlendMode(null);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
2021-06-25 02:43:10 +02:00
|
|
|
if (colorFilter != null && gradientShader == 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;
|
2019-07-18 15:01:39 +02:00
|
|
|
if (bitmapDrawable instanceof AnimatedFileDrawable || bitmapDrawable instanceof RLottieDrawable) {
|
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 {
|
2020-10-02 13:25:02 +02:00
|
|
|
Bitmap bitmap = bitmapDrawable.getBitmap();
|
|
|
|
if (bitmap != null && bitmap.isRecycled()) {
|
|
|
|
return;
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
if (orientation % 360 == 90 || orientation % 360 == 270) {
|
2020-10-02 13:25:02 +02:00
|
|
|
bitmapW = bitmap.getHeight();
|
|
|
|
bitmapH = bitmap.getWidth();
|
2016-04-22 15:49:00 +02:00
|
|
|
} else {
|
2020-10-02 13:25:02 +02:00
|
|
|
bitmapW = bitmap.getWidth();
|
|
|
|
bitmapH = bitmap.getHeight();
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
2022-11-05 13:34:47 +01:00
|
|
|
reactionLastFrame = bitmapDrawable instanceof ReactionLastFrame;
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
float realImageW = imageW - sideClip * 2;
|
|
|
|
float realImageH = imageH - sideClip * 2;
|
|
|
|
float scaleW = imageW == 0 ? 1.0f : (bitmapW / realImageW);
|
|
|
|
float scaleH = imageH == 0 ? 1.0f : (bitmapH / realImageH);
|
|
|
|
|
2022-11-05 13:34:47 +01:00
|
|
|
if (reactionLastFrame) {
|
|
|
|
scaleW /= ReactionLastFrame.LAST_FRAME_SCALE;
|
|
|
|
scaleH /= ReactionLastFrame.LAST_FRAME_SCALE;
|
|
|
|
}
|
2022-08-12 17:23:51 +02:00
|
|
|
if (shader != null && backgroundThreadDrawHolder == null) {
|
2019-05-14 14:08:05 +02:00
|
|
|
if (isAspectFit) {
|
|
|
|
float scale = Math.max(scaleW, scaleH);
|
|
|
|
bitmapW /= scale;
|
|
|
|
bitmapH /= scale;
|
|
|
|
drawRegion.set(imageX + (imageW - bitmapW) / 2, imageY + (imageH - bitmapH) / 2, imageX + (imageW + bitmapW) / 2, imageY + (imageH + bitmapH) / 2);
|
|
|
|
|
|
|
|
if (isVisible) {
|
|
|
|
shaderMatrix.reset();
|
2022-06-21 04:51:00 +02:00
|
|
|
shaderMatrix.setTranslate((int) drawRegion.left, (int) drawRegion.top);
|
|
|
|
float toScale = 1.0f / scale;
|
2019-05-14 14:08:05 +02:00
|
|
|
shaderMatrix.preScale(1.0f / scale, 1.0f / scale);
|
|
|
|
|
|
|
|
shader.setLocalMatrix(shaderMatrix);
|
2022-06-21 04:51:00 +02:00
|
|
|
roundPaint.setShader(shader);
|
2019-05-14 14:08:05 +02:00
|
|
|
roundPaint.setAlpha(alpha);
|
|
|
|
roundRect.set(drawRegion);
|
2020-01-23 07:15:40 +01:00
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
if (isRoundRect) {
|
2020-08-22 01:59:49 +02:00
|
|
|
try {
|
2022-12-06 20:13:44 +01:00
|
|
|
if (canvas != null) {
|
|
|
|
if (roundRadius[0] == 0) {
|
|
|
|
canvas.drawRect(roundRect, roundPaint);
|
|
|
|
} else {
|
|
|
|
canvas.drawRoundRect(roundRect, roundRadius[0], roundRadius[0], roundPaint);
|
|
|
|
}
|
2021-11-05 11:06:49 +01:00
|
|
|
}
|
2020-08-22 01:59:49 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
onBitmapException(bitmapDrawable);
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2020-06-04 18:47:15 +02:00
|
|
|
} else {
|
|
|
|
for (int a = 0; a < roundRadius.length; a++) {
|
|
|
|
radii[a * 2] = roundRadius[a];
|
|
|
|
radii[a * 2 + 1] = roundRadius[a];
|
|
|
|
}
|
|
|
|
roundPath.reset();
|
|
|
|
roundPath.addRoundRect(roundRect, radii, Path.Direction.CW);
|
|
|
|
roundPath.close();
|
2022-12-06 20:13:44 +01:00
|
|
|
if (canvas != null) {
|
|
|
|
canvas.drawPath(roundPath, roundPaint);
|
|
|
|
}
|
2020-01-23 07:15:40 +01:00
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
|
|
|
} else {
|
2021-06-25 02:43:10 +02:00
|
|
|
if (legacyCanvas != null) {
|
|
|
|
roundRect.set(0, 0, legacyBitmap.getWidth(), legacyBitmap.getHeight());
|
|
|
|
legacyCanvas.drawBitmap(gradientBitmap, null, roundRect, null);
|
|
|
|
legacyCanvas.drawBitmap(bitmapDrawable.getBitmap(), null, roundRect, legacyPaint);
|
|
|
|
}
|
|
|
|
if (shader == imageShader && gradientShader != null) {
|
|
|
|
if (composeShader != null) {
|
|
|
|
roundPaint.setShader(composeShader);
|
|
|
|
} else {
|
|
|
|
roundPaint.setShader(legacyShader);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
roundPaint.setShader(shader);
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
float scale = 1.0f / Math.min(scaleW, scaleH);
|
|
|
|
roundRect.set(imageX + sideClip, imageY + sideClip, imageX + imageW - sideClip, imageY + imageH - sideClip);
|
2019-03-03 21:40:48 +01:00
|
|
|
if (Math.abs(scaleW - scaleH) > 0.0005f) {
|
2019-05-14 14:08:05 +02:00
|
|
|
if (bitmapW / scaleH > realImageW) {
|
|
|
|
bitmapW /= scaleH;
|
|
|
|
drawRegion.set(imageX - (bitmapW - realImageW) / 2, imageY, imageX + (bitmapW + realImageW) / 2, imageY + realImageH);
|
|
|
|
} else {
|
|
|
|
bitmapH /= scaleW;
|
|
|
|
drawRegion.set(imageX, imageY - (bitmapH - realImageH) / 2, imageX + realImageW, imageY + (bitmapH + realImageH) / 2);
|
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
} else {
|
2019-05-14 14:08:05 +02:00
|
|
|
drawRegion.set(imageX, imageY, imageX + realImageW, imageY + realImageH);
|
|
|
|
}
|
|
|
|
if (isVisible) {
|
|
|
|
shaderMatrix.reset();
|
2022-11-05 13:34:47 +01:00
|
|
|
if (reactionLastFrame) {
|
|
|
|
shaderMatrix.setTranslate((int) (drawRegion.left + sideClip) - (drawRegion.width() * ReactionLastFrame.LAST_FRAME_SCALE - drawRegion.width()) / 2f, (int) (drawRegion.top + sideClip) - (drawRegion.height() * ReactionLastFrame.LAST_FRAME_SCALE - drawRegion.height()) / 2f);
|
|
|
|
} else {
|
|
|
|
shaderMatrix.setTranslate((int) (drawRegion.left + sideClip), (int) (drawRegion.top + sideClip));
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
if (orientation == 90) {
|
|
|
|
shaderMatrix.preRotate(90);
|
|
|
|
shaderMatrix.preTranslate(0, -drawRegion.width());
|
|
|
|
} else if (orientation == 180) {
|
|
|
|
shaderMatrix.preRotate(180);
|
|
|
|
shaderMatrix.preTranslate(-drawRegion.width(), -drawRegion.height());
|
|
|
|
} else if (orientation == 270) {
|
|
|
|
shaderMatrix.preRotate(270);
|
|
|
|
shaderMatrix.preTranslate(-drawRegion.height(), 0);
|
|
|
|
}
|
|
|
|
shaderMatrix.preScale(scale, scale);
|
2019-12-31 14:08:08 +01:00
|
|
|
if (isRoundVideo) {
|
|
|
|
float postScale = (realImageW + AndroidUtilities.roundMessageInset * 2) / realImageW;
|
|
|
|
shaderMatrix.postScale(postScale, postScale, drawRegion.centerX(), drawRegion.centerY());
|
|
|
|
}
|
2021-06-25 02:43:10 +02:00
|
|
|
if (legacyShader != null) {
|
|
|
|
legacyShader.setLocalMatrix(shaderMatrix);
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
shader.setLocalMatrix(shaderMatrix);
|
2021-06-25 02:43:10 +02:00
|
|
|
|
|
|
|
if (composeShader != null) {
|
|
|
|
int bitmapW2 = gradientBitmap.getWidth();
|
|
|
|
int bitmapH2 = gradientBitmap.getHeight();
|
|
|
|
float scaleW2 = imageW == 0 ? 1.0f : (bitmapW2 / realImageW);
|
|
|
|
float scaleH2 = imageH == 0 ? 1.0f : (bitmapH2 / realImageH);
|
|
|
|
if (Math.abs(scaleW2 - scaleH2) > 0.0005f) {
|
|
|
|
if (bitmapW2 / scaleH2 > realImageW) {
|
|
|
|
bitmapW2 /= scaleH2;
|
|
|
|
drawRegion.set(imageX - (bitmapW2 - realImageW) / 2, imageY, imageX + (bitmapW2 + realImageW) / 2, imageY + realImageH);
|
|
|
|
} else {
|
|
|
|
bitmapH2 /= scaleW2;
|
|
|
|
drawRegion.set(imageX, imageY - (bitmapH2 - realImageH) / 2, imageX + realImageW, imageY + (bitmapH2 + realImageH) / 2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
drawRegion.set(imageX, imageY, imageX + realImageW, imageY + realImageH);
|
|
|
|
}
|
|
|
|
scale = 1.0f / Math.min(imageW == 0 ? 1.0f : (bitmapW2 / realImageW), imageH == 0 ? 1.0f : (bitmapH2 / realImageH));
|
|
|
|
|
|
|
|
shaderMatrix.reset();
|
|
|
|
shaderMatrix.setTranslate(drawRegion.left + sideClip, drawRegion.top + sideClip);
|
|
|
|
shaderMatrix.preScale(scale, scale);
|
|
|
|
gradientShader.setLocalMatrix(shaderMatrix);
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
roundPaint.setAlpha(alpha);
|
2020-01-23 07:15:40 +01:00
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
if (isRoundRect) {
|
2020-08-22 01:59:49 +02:00
|
|
|
try {
|
2022-12-06 20:13:44 +01:00
|
|
|
if (canvas != null) {
|
|
|
|
if (roundRadius[0] == 0) {
|
|
|
|
if (reactionLastFrame) {
|
|
|
|
AndroidUtilities.rectTmp.set(roundRect);
|
|
|
|
AndroidUtilities.rectTmp.inset(-(drawRegion.width() * ReactionLastFrame.LAST_FRAME_SCALE - drawRegion.width()) / 2f, -(drawRegion.height() * ReactionLastFrame.LAST_FRAME_SCALE - drawRegion.height()) / 2f);
|
|
|
|
canvas.drawRect(AndroidUtilities.rectTmp, roundPaint);
|
|
|
|
} else {
|
|
|
|
canvas.drawRect(roundRect, roundPaint);
|
|
|
|
}
|
2022-11-05 13:34:47 +01:00
|
|
|
} else {
|
2022-12-06 20:13:44 +01:00
|
|
|
canvas.drawRoundRect(roundRect, roundRadius[0], roundRadius[0], roundPaint);
|
2022-11-05 13:34:47 +01:00
|
|
|
}
|
2021-11-05 11:06:49 +01:00
|
|
|
}
|
2020-08-22 01:59:49 +02:00
|
|
|
} catch (Exception e) {
|
2022-08-12 17:23:51 +02:00
|
|
|
if (backgroundThreadDrawHolder == null) {
|
|
|
|
onBitmapException(bitmapDrawable);
|
|
|
|
}
|
2020-08-22 01:59:49 +02:00
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2020-06-04 18:47:15 +02:00
|
|
|
} else {
|
|
|
|
for (int a = 0; a < roundRadius.length; a++) {
|
|
|
|
radii[a * 2] = roundRadius[a];
|
|
|
|
radii[a * 2 + 1] = roundRadius[a];
|
|
|
|
}
|
|
|
|
roundPath.reset();
|
|
|
|
roundPath.addRoundRect(roundRect, radii, Path.Direction.CW);
|
|
|
|
roundPath.close();
|
2022-12-06 20:13:44 +01:00
|
|
|
if (canvas != null) {
|
|
|
|
canvas.drawPath(roundPath, roundPaint);
|
|
|
|
}
|
2020-01-23 07:15:40 +01:00
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (isAspectFit) {
|
|
|
|
float scale = Math.max(scaleW, scaleH);
|
|
|
|
canvas.save();
|
|
|
|
bitmapW /= scale;
|
|
|
|
bitmapH /= scale;
|
2022-08-12 17:23:51 +02:00
|
|
|
if (backgroundThreadDrawHolder == null) {
|
|
|
|
drawRegion.set(imageX + (imageW - bitmapW) / 2.0f, imageY + (imageH - bitmapH) / 2.0f, imageX + (imageW + bitmapW) / 2.0f, imageY + (imageH + bitmapH) / 2.0f);
|
|
|
|
bitmapDrawable.setBounds((int) drawRegion.left, (int) drawRegion.top, (int) drawRegion.right, (int) drawRegion.bottom);
|
|
|
|
if (bitmapDrawable instanceof AnimatedFileDrawable) {
|
|
|
|
((AnimatedFileDrawable) bitmapDrawable).setActualDrawRect(drawRegion.left, drawRegion.top, drawRegion.width(), drawRegion.height());
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
2022-09-16 20:48:21 +02:00
|
|
|
if (backgroundThreadDrawHolder != null && roundRadius != null && roundRadius[0] > 0) {
|
|
|
|
canvas.save();
|
|
|
|
Path path = backgroundThreadDrawHolder.roundPath == null ? backgroundThreadDrawHolder.roundPath = new Path() : backgroundThreadDrawHolder.roundPath;
|
|
|
|
path.rewind();
|
|
|
|
AndroidUtilities.rectTmp.set(imageX, imageY, imageX + imageW, imageY + imageH);
|
|
|
|
path.addRoundRect(AndroidUtilities.rectTmp, roundRadius[0], roundRadius[2], Path.Direction.CW);
|
|
|
|
canvas.clipPath(path);
|
|
|
|
}
|
2019-02-08 03:30:32 +01:00
|
|
|
if (isVisible) {
|
|
|
|
try {
|
|
|
|
bitmapDrawable.setAlpha(alpha);
|
2022-08-12 17:23:51 +02:00
|
|
|
drawBitmapDrawable(canvas, bitmapDrawable, backgroundThreadDrawHolder, alpha);
|
2019-02-08 03:30:32 +01:00
|
|
|
} catch (Exception e) {
|
2022-08-12 17:23:51 +02:00
|
|
|
if (backgroundThreadDrawHolder == null) {
|
|
|
|
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();
|
2022-09-16 20:48:21 +02:00
|
|
|
if (backgroundThreadDrawHolder != null && roundRadius != null && roundRadius[0] > 0) {
|
|
|
|
canvas.restore();
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} else {
|
2022-12-06 20:13:44 +01:00
|
|
|
if (canvas != null) {
|
|
|
|
if (Math.abs(scaleW - scaleH) > 0.00001f) {
|
|
|
|
canvas.save();
|
|
|
|
if (clip) {
|
|
|
|
canvas.clipRect(imageX, imageY, imageX + imageW, imageY + imageH);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2022-12-06 20:13:44 +01:00
|
|
|
if (orientation % 360 != 0) {
|
|
|
|
if (centerRotation) {
|
|
|
|
canvas.rotate(orientation, imageW / 2, imageH / 2);
|
|
|
|
} else {
|
|
|
|
canvas.rotate(orientation, 0, 0);
|
|
|
|
}
|
2014-10-01 21:55:24 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2022-12-06 20:13:44 +01:00
|
|
|
if (bitmapW / scaleH > imageW) {
|
|
|
|
bitmapW /= scaleH;
|
|
|
|
drawRegion.set(imageX - (bitmapW - imageW) / 2.0f, imageY, imageX + (bitmapW + imageW) / 2.0f, imageY + imageH);
|
2022-08-12 17:23:51 +02:00
|
|
|
} else {
|
2022-12-06 20:13:44 +01:00
|
|
|
bitmapH /= scaleW;
|
|
|
|
drawRegion.set(imageX, imageY - (bitmapH - imageH) / 2.0f, imageX + imageW, imageY + (bitmapH + imageH) / 2.0f);
|
2022-08-12 17:23:51 +02:00
|
|
|
}
|
2022-12-06 20:13:44 +01:00
|
|
|
if (bitmapDrawable instanceof AnimatedFileDrawable) {
|
|
|
|
((AnimatedFileDrawable) bitmapDrawable).setActualDrawRect(imageX, imageY, imageW, imageH);
|
|
|
|
}
|
|
|
|
if (backgroundThreadDrawHolder == null) {
|
|
|
|
if (orientation % 360 == 90 || orientation % 360 == 270) {
|
|
|
|
float width = drawRegion.width() / 2;
|
|
|
|
float height = drawRegion.height() / 2;
|
|
|
|
float centerX = drawRegion.centerX();
|
|
|
|
float centerY = drawRegion.centerY();
|
|
|
|
bitmapDrawable.setBounds((int) (centerX - height), (int) (centerY - width), (int) (centerX + height), (int) (centerY + width));
|
|
|
|
} else {
|
|
|
|
bitmapDrawable.setBounds((int) drawRegion.left, (int) drawRegion.top, (int) drawRegion.right, (int) drawRegion.bottom);
|
2021-06-25 02:43:10 +02:00
|
|
|
}
|
2022-12-06 20:13:44 +01:00
|
|
|
}
|
|
|
|
if (isVisible) {
|
|
|
|
try {
|
|
|
|
if (Build.VERSION.SDK_INT >= 29) {
|
|
|
|
if (blendMode != null) {
|
|
|
|
bitmapDrawable.getPaint().setBlendMode((BlendMode) blendMode);
|
|
|
|
} else {
|
|
|
|
bitmapDrawable.getPaint().setBlendMode(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drawBitmapDrawable(canvas, bitmapDrawable, backgroundThreadDrawHolder, alpha);
|
|
|
|
} catch (Exception e) {
|
|
|
|
if (backgroundThreadDrawHolder == null) {
|
|
|
|
onBitmapException(bitmapDrawable);
|
|
|
|
}
|
|
|
|
FileLog.e(e);
|
2022-08-12 17:23:51 +02:00
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
|
2022-12-06 20:13:44 +01:00
|
|
|
canvas.restore();
|
|
|
|
} else {
|
|
|
|
canvas.save();
|
|
|
|
if (orientation % 360 != 0) {
|
|
|
|
if (centerRotation) {
|
|
|
|
canvas.rotate(orientation, imageW / 2, imageH / 2);
|
|
|
|
} else {
|
|
|
|
canvas.rotate(orientation, 0, 0);
|
|
|
|
}
|
2014-10-21 22:35:16 +02:00
|
|
|
}
|
2022-12-06 20:13:44 +01:00
|
|
|
drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
|
|
|
|
if (isRoundVideo) {
|
|
|
|
drawRegion.inset(-AndroidUtilities.roundMessageInset, -AndroidUtilities.roundMessageInset);
|
2022-08-12 17:23:51 +02:00
|
|
|
}
|
2022-12-06 20:13:44 +01:00
|
|
|
if (bitmapDrawable instanceof AnimatedFileDrawable) {
|
|
|
|
((AnimatedFileDrawable) bitmapDrawable).setActualDrawRect(imageX, imageY, imageW, imageH);
|
|
|
|
}
|
|
|
|
if (backgroundThreadDrawHolder == null) {
|
|
|
|
if (orientation % 360 == 90 || orientation % 360 == 270) {
|
|
|
|
float width = drawRegion.width() / 2;
|
|
|
|
float height = drawRegion.height() / 2;
|
|
|
|
float centerX = drawRegion.centerX();
|
|
|
|
float centerY = drawRegion.centerY();
|
|
|
|
bitmapDrawable.setBounds((int) (centerX - height), (int) (centerY - width), (int) (centerX + height), (int) (centerY + width));
|
|
|
|
} else {
|
|
|
|
bitmapDrawable.setBounds((int) drawRegion.left, (int) drawRegion.top, (int) drawRegion.right, (int) drawRegion.bottom);
|
2021-06-25 02:43:10 +02:00
|
|
|
}
|
2022-12-06 20:13:44 +01:00
|
|
|
}
|
|
|
|
if (isVisible) {
|
|
|
|
try {
|
|
|
|
if (Build.VERSION.SDK_INT >= 29) {
|
|
|
|
if (blendMode != null) {
|
|
|
|
bitmapDrawable.getPaint().setBlendMode((BlendMode) blendMode);
|
|
|
|
} else {
|
|
|
|
bitmapDrawable.getPaint().setBlendMode(null);
|
|
|
|
}
|
|
|
|
}
|
2022-08-12 17:23:51 +02:00
|
|
|
|
2022-12-06 20:13:44 +01:00
|
|
|
drawBitmapDrawable(canvas, bitmapDrawable, backgroundThreadDrawHolder, alpha);
|
|
|
|
} catch (Exception e) {
|
|
|
|
onBitmapException(bitmapDrawable);
|
|
|
|
FileLog.e(e);
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2022-12-06 20:13:44 +01:00
|
|
|
canvas.restore();
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-12 17:23:51 +02:00
|
|
|
|
|
|
|
if (drawable instanceof RLottieDrawable) {
|
|
|
|
((RLottieDrawable) drawable).skipFrameUpdate = false;
|
|
|
|
} else if (drawable instanceof AnimatedFileDrawable) {
|
|
|
|
((AnimatedFileDrawable) drawable).skipFrameUpdate = false;
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} else {
|
2022-08-12 17:23:51 +02:00
|
|
|
if (backgroundThreadDrawHolder == null) {
|
|
|
|
if (isAspectFit) {
|
|
|
|
int bitmapW = drawable.getIntrinsicWidth();
|
|
|
|
int bitmapH = drawable.getIntrinsicHeight();
|
|
|
|
float realImageW = imageW - sideClip * 2;
|
|
|
|
float realImageH = imageH - sideClip * 2;
|
|
|
|
float scaleW = imageW == 0 ? 1.0f : (bitmapW / realImageW);
|
|
|
|
float scaleH = imageH == 0 ? 1.0f : (bitmapH / realImageH);
|
|
|
|
float scale = Math.max(scaleW, scaleH);
|
|
|
|
bitmapW /= scale;
|
|
|
|
bitmapH /= scale;
|
|
|
|
drawRegion.set(imageX + (imageW - bitmapW) / 2.0f, imageY + (imageH - bitmapH) / 2.0f, imageX + (imageW + bitmapW) / 2.0f, imageY + (imageH + bitmapH) / 2.0f);
|
|
|
|
} else {
|
|
|
|
drawRegion.set(imageX, imageY, imageX + imageW, imageY + imageH);
|
|
|
|
}
|
|
|
|
drawable.setBounds((int) drawRegion.left, (int) drawRegion.top, (int) drawRegion.right, (int) drawRegion.bottom);
|
2021-01-01 05:38:45 +01:00
|
|
|
}
|
2022-12-06 20:13:44 +01:00
|
|
|
if (isVisible && canvas != null) {
|
2015-05-03 13:48:36 +02:00
|
|
|
try {
|
|
|
|
drawable.setAlpha(alpha);
|
2022-08-12 17:23:51 +02:00
|
|
|
if (backgroundThreadDrawHolder != null) {
|
|
|
|
if (drawable instanceof SvgHelper.SvgDrawable) {
|
|
|
|
long time = backgroundThreadDrawHolder.time;
|
|
|
|
if (time == 0) {
|
|
|
|
time = System.currentTimeMillis();
|
|
|
|
}
|
2022-11-12 09:41:35 +01:00
|
|
|
((SvgHelper.SvgDrawable) drawable).drawInternal(canvas, true, backgroundThreadDrawHolder.threadIndex, time, backgroundThreadDrawHolder.imageX, backgroundThreadDrawHolder.imageY, backgroundThreadDrawHolder.imageW, backgroundThreadDrawHolder.imageH);
|
2022-08-12 17:23:51 +02:00
|
|
|
} else {
|
|
|
|
drawable.draw(canvas);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
drawable.draw(canvas);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-12 17:23:51 +02:00
|
|
|
private void drawBitmapDrawable(Canvas canvas, BitmapDrawable bitmapDrawable, BackgroundThreadDrawHolder backgroundThreadDrawHolder, int alpha) {
|
|
|
|
if (backgroundThreadDrawHolder != null) {
|
|
|
|
if (bitmapDrawable instanceof RLottieDrawable) {
|
2022-11-12 09:41:35 +01:00
|
|
|
((RLottieDrawable) bitmapDrawable).drawInBackground(canvas, backgroundThreadDrawHolder.imageX, backgroundThreadDrawHolder.imageY, backgroundThreadDrawHolder.imageW, backgroundThreadDrawHolder.imageH, alpha, backgroundThreadDrawHolder.colorFilter, backgroundThreadDrawHolder.threadIndex);
|
2022-08-12 17:23:51 +02:00
|
|
|
} else if (bitmapDrawable instanceof AnimatedFileDrawable) {
|
2022-11-12 09:41:35 +01:00
|
|
|
((AnimatedFileDrawable) bitmapDrawable).drawInBackground(canvas, backgroundThreadDrawHolder.imageX, backgroundThreadDrawHolder.imageY, backgroundThreadDrawHolder.imageW, backgroundThreadDrawHolder.imageH, alpha, backgroundThreadDrawHolder.colorFilter, backgroundThreadDrawHolder.threadIndex);
|
2022-08-12 17:23:51 +02:00
|
|
|
} else {
|
|
|
|
Bitmap bitmap = bitmapDrawable.getBitmap();
|
|
|
|
if (bitmap != null) {
|
|
|
|
if (backgroundThreadDrawHolder.paint == null) {
|
|
|
|
backgroundThreadDrawHolder.paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
|
}
|
|
|
|
backgroundThreadDrawHolder.paint.setAlpha(alpha);
|
2022-09-16 20:48:21 +02:00
|
|
|
backgroundThreadDrawHolder.paint.setColorFilter(backgroundThreadDrawHolder.colorFilter);
|
2022-08-12 17:23:51 +02:00
|
|
|
canvas.save();
|
|
|
|
canvas.translate(backgroundThreadDrawHolder.imageX, backgroundThreadDrawHolder.imageY);
|
|
|
|
canvas.scale(backgroundThreadDrawHolder.imageW / bitmap.getWidth(), backgroundThreadDrawHolder.imageH / bitmap.getHeight());
|
|
|
|
canvas.drawBitmap(bitmap, 0, 0, backgroundThreadDrawHolder.paint);
|
|
|
|
canvas.restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bitmapDrawable.setAlpha(alpha);
|
|
|
|
if (bitmapDrawable instanceof RLottieDrawable) {
|
2022-12-06 20:13:44 +01:00
|
|
|
((RLottieDrawable) bitmapDrawable).drawInternal(canvas, null, false, currentTime, 0);
|
2022-08-12 17:23:51 +02:00
|
|
|
} else if (bitmapDrawable instanceof AnimatedFileDrawable) {
|
2022-11-12 09:41:35 +01:00
|
|
|
((AnimatedFileDrawable) bitmapDrawable).drawInternal(canvas, false, currentTime, 0);
|
2022-08-12 17:23:51 +02:00
|
|
|
} else {
|
|
|
|
bitmapDrawable.draw(canvas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-25 02:43:10 +02:00
|
|
|
public void setBlendMode(Object mode) {
|
|
|
|
blendMode = mode;
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setGradientBitmap(Bitmap bitmap) {
|
|
|
|
if (bitmap != null) {
|
|
|
|
if (gradientShader == null || gradientBitmap != bitmap) {
|
|
|
|
gradientShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
|
|
|
|
updateDrawableRadius(currentImageDrawable);
|
|
|
|
}
|
|
|
|
isRoundRect = true;
|
|
|
|
} else {
|
|
|
|
gradientShader = null;
|
|
|
|
composeShader = null;
|
|
|
|
legacyShader = null;
|
|
|
|
legacyCanvas = null;
|
|
|
|
if (legacyBitmap != null) {
|
|
|
|
legacyBitmap.recycle();
|
|
|
|
legacyBitmap = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gradientBitmap = bitmap;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
setImage(currentMediaLocation, currentMediaFilter, currentImageLocation, currentImageFilter, currentThumbLocation, currentThumbFilter, currentThumbDrawable, currentSize, currentExt, currentParentObject, currentCacheType);
|
2019-03-03 21:40:48 +01:00
|
|
|
}
|
|
|
|
|
2022-09-16 20:48:21 +02:00
|
|
|
private void checkAlphaAnimation(boolean skip, BackgroundThreadDrawHolder backgroundThreadDrawHolder) {
|
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) {
|
2022-09-16 20:48:21 +02:00
|
|
|
if (backgroundThreadDrawHolder != null) {
|
2022-08-12 17:23:51 +02:00
|
|
|
long currentTime = System.currentTimeMillis();
|
|
|
|
long dt = currentTime - lastUpdateAlphaTime;
|
|
|
|
if (lastUpdateAlphaTime == 0) {
|
|
|
|
dt = 16;
|
|
|
|
}
|
|
|
|
if (dt > 30 && AndroidUtilities.screenRefreshRate > 60) {
|
|
|
|
dt = 30;
|
|
|
|
}
|
|
|
|
currentAlpha += dt / (float) crossfadeDuration;
|
|
|
|
} else {
|
|
|
|
currentAlpha += 16f / (float) crossfadeDuration;
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
if (currentAlpha > 1) {
|
|
|
|
currentAlpha = 1;
|
2022-01-10 03:27:47 +01:00
|
|
|
previousAlpha = 1f;
|
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
|
|
|
}
|
2022-09-16 20:48:21 +02:00
|
|
|
if (backgroundThreadDrawHolder != null) {
|
|
|
|
AndroidUtilities.runOnUIThread(this::invalidate);
|
|
|
|
} else {
|
|
|
|
invalidate();
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-30 11:26:29 +01:00
|
|
|
public void skipDraw() {
|
2022-08-12 17:23:51 +02:00
|
|
|
// RLottieDrawable lottieDrawable = getLottieAnimation();
|
|
|
|
// if (lottieDrawable != null) {
|
|
|
|
// lottieDrawable.setCurrentParentView(parentView);
|
|
|
|
// lottieDrawable.updateCurrentFrame();
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean customDraw(
|
|
|
|
Canvas canvas,
|
|
|
|
AnimatedFileDrawable animation,
|
|
|
|
RLottieDrawable lottieAnimation,
|
|
|
|
Drawable currentMediaDrawable, BitmapShader currentMediaShader,
|
|
|
|
Drawable currentImageDrawable, BitmapShader currentImageShader,
|
|
|
|
Drawable currentThumbDrawable, BitmapShader currentThumbShader,
|
|
|
|
boolean crossfadeWithOldImage, boolean crossfadingWithThumb,
|
|
|
|
Drawable crossfadeImage, BitmapShader crossfadeShader,
|
|
|
|
Drawable staticThumbDrawable,
|
|
|
|
float currentAlpha, float previousAlpha, float overrideAlpha,
|
|
|
|
int[] roundRadius,
|
|
|
|
BackgroundThreadDrawHolder backgroundThreadDrawHolder
|
|
|
|
) {
|
|
|
|
return false;
|
2020-10-30 11:26:29 +01:00
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
public boolean draw(Canvas canvas) {
|
2022-08-12 17:23:51 +02:00
|
|
|
return draw(canvas, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean draw(Canvas canvas, BackgroundThreadDrawHolder backgroundThreadDrawHolder) {
|
2021-06-25 02:43:10 +02:00
|
|
|
boolean result = false;
|
|
|
|
if (gradientBitmap != null && currentImageKey != null) {
|
|
|
|
canvas.save();
|
|
|
|
canvas.clipRect(imageX, imageY, imageX + imageW, imageY + imageH);
|
|
|
|
canvas.drawColor(0xff000000);
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
try {
|
2016-01-11 18:19:48 +01:00
|
|
|
Drawable drawable = null;
|
2022-08-12 17:23:51 +02:00
|
|
|
AnimatedFileDrawable animation;
|
|
|
|
RLottieDrawable lottieDrawable;
|
|
|
|
Drawable currentMediaDrawable;
|
|
|
|
BitmapShader mediaShader;
|
|
|
|
Drawable currentImageDrawable;
|
|
|
|
BitmapShader imageShader;
|
|
|
|
Drawable currentThumbDrawable;
|
|
|
|
BitmapShader thumbShader;
|
|
|
|
|
|
|
|
boolean crossfadeWithOldImage;
|
|
|
|
boolean crossfadingWithThumb;
|
|
|
|
Drawable crossfadeImage;
|
|
|
|
BitmapShader crossfadeShader;
|
|
|
|
Drawable staticThumbDrawable;
|
|
|
|
float currentAlpha;
|
|
|
|
float previousAlpha;
|
|
|
|
float overrideAlpha;
|
|
|
|
|
|
|
|
int[] roundRadius;
|
|
|
|
boolean animationNotReady;
|
|
|
|
boolean drawInBackground = backgroundThreadDrawHolder != null;
|
|
|
|
if (drawInBackground) {
|
|
|
|
animation = backgroundThreadDrawHolder.animation;
|
|
|
|
lottieDrawable = backgroundThreadDrawHolder.lottieDrawable;
|
|
|
|
roundRadius = backgroundThreadDrawHolder.roundRadius;
|
|
|
|
currentMediaDrawable = backgroundThreadDrawHolder.mediaDrawable;
|
|
|
|
mediaShader = backgroundThreadDrawHolder.mediaShader;
|
|
|
|
currentImageDrawable = backgroundThreadDrawHolder.imageDrawable;
|
|
|
|
imageShader = backgroundThreadDrawHolder.imageShader;
|
|
|
|
thumbShader = backgroundThreadDrawHolder.thumbShader;
|
|
|
|
crossfadeImage = backgroundThreadDrawHolder.crossfadeImage;
|
|
|
|
crossfadeWithOldImage = backgroundThreadDrawHolder.crossfadeWithOldImage;
|
|
|
|
crossfadingWithThumb = backgroundThreadDrawHolder.crossfadingWithThumb;
|
|
|
|
currentThumbDrawable = backgroundThreadDrawHolder.thumbDrawable;
|
|
|
|
staticThumbDrawable = backgroundThreadDrawHolder.staticThumbDrawable;
|
|
|
|
currentAlpha = backgroundThreadDrawHolder.currentAlpha;
|
|
|
|
previousAlpha = backgroundThreadDrawHolder.previousAlpha;
|
|
|
|
crossfadeShader = backgroundThreadDrawHolder.crossfadeShader;
|
|
|
|
animationNotReady = backgroundThreadDrawHolder.animationNotReady;
|
|
|
|
overrideAlpha = backgroundThreadDrawHolder.overrideAlpha;
|
|
|
|
} else {
|
|
|
|
animation = getAnimation();
|
|
|
|
lottieDrawable = getLottieAnimation();
|
|
|
|
roundRadius = this.roundRadius;
|
|
|
|
currentMediaDrawable = this.currentMediaDrawable;
|
|
|
|
mediaShader = this.mediaShader;
|
|
|
|
currentImageDrawable = this.currentImageDrawable;
|
|
|
|
imageShader = this.imageShader;
|
|
|
|
currentThumbDrawable = this.currentThumbDrawable;
|
|
|
|
thumbShader = this.thumbShader;
|
|
|
|
crossfadeWithOldImage = this.crossfadeWithOldImage;
|
|
|
|
crossfadingWithThumb = this.crossfadingWithThumb;
|
|
|
|
crossfadeImage = this.crossfadeImage;
|
|
|
|
staticThumbDrawable = this.staticThumbDrawable;
|
|
|
|
currentAlpha = this.currentAlpha;
|
|
|
|
previousAlpha = this.previousAlpha;
|
|
|
|
crossfadeShader = this.crossfadeShader;
|
|
|
|
overrideAlpha = this.overrideAlpha;
|
|
|
|
animationNotReady = animation != null && !animation.hasBitmap() || lottieDrawable != null && !lottieDrawable.hasBitmap();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (customDraw(
|
|
|
|
canvas,
|
|
|
|
animation, lottieDrawable,
|
|
|
|
currentMediaDrawable, mediaShader,
|
|
|
|
currentImageDrawable, imageShader,
|
|
|
|
currentThumbDrawable, thumbShader,
|
|
|
|
crossfadeWithOldImage, crossfadingWithThumb,
|
|
|
|
crossfadeImage, crossfadeShader,
|
|
|
|
staticThumbDrawable,
|
|
|
|
currentAlpha, previousAlpha, overrideAlpha,
|
|
|
|
roundRadius, backgroundThreadDrawHolder
|
|
|
|
)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-26 10:03:38 +02:00
|
|
|
if (animation != null) {
|
|
|
|
animation.setRoundRadius(roundRadius);
|
|
|
|
}
|
2022-08-12 17:23:51 +02:00
|
|
|
if (lottieDrawable != null && !drawInBackground) {
|
2019-07-18 15:01:39 +02:00
|
|
|
lottieDrawable.setCurrentParentView(parentView);
|
|
|
|
}
|
2022-08-12 17:23:51 +02:00
|
|
|
if ((animation != null || lottieDrawable != null) && !animationNotReady && !animationReadySent && !drawInBackground) {
|
2019-08-22 01:53:26 +02:00
|
|
|
animationReadySent = true;
|
|
|
|
if (delegate != null) {
|
|
|
|
delegate.onAnimationReady(this);
|
|
|
|
}
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
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;
|
2022-02-03 23:18:58 +01:00
|
|
|
if (useRoundForThumb && thumbShader == null) {
|
|
|
|
updateDrawableRadius(staticThumbDrawable);
|
2022-08-12 17:23:51 +02:00
|
|
|
thumbShader = this.thumbShader;
|
2022-02-03 23:18:58 +01:00
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
shaderToUse = thumbShader;
|
|
|
|
orientation = thumbOrientation;
|
|
|
|
} else if (currentThumbDrawable != null) {
|
|
|
|
drawable = currentThumbDrawable;
|
|
|
|
shaderToUse = thumbShader;
|
|
|
|
orientation = thumbOrientation;
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2022-02-01 14:00:45 +01:00
|
|
|
|
2022-11-06 02:16:18 +01:00
|
|
|
float crossfadeProgress = currentAlpha;
|
|
|
|
if (crossfadeByScale > 0) {
|
|
|
|
currentAlpha = Math.min(currentAlpha + crossfadeByScale * currentAlpha, 1);
|
|
|
|
}
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
if (drawable != null) {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (crossfadeAlpha != 0) {
|
2022-01-10 03:27:47 +01:00
|
|
|
if (previousAlpha != 1f && (drawable == currentImageDrawable || drawable == currentMediaDrawable) && staticThumbDrawable != null) {
|
2022-02-03 23:18:58 +01:00
|
|
|
if (useRoundForThumb && thumbShader == null) {
|
|
|
|
updateDrawableRadius(staticThumbDrawable);
|
2022-08-12 17:23:51 +02:00
|
|
|
thumbShader = this.thumbShader;
|
2022-02-03 23:18:58 +01:00
|
|
|
}
|
2022-08-12 17:23:51 +02:00
|
|
|
drawDrawable(canvas, staticThumbDrawable, (int) (overrideAlpha * 255), thumbShader, orientation, backgroundThreadDrawHolder);
|
2022-01-10 03:27:47 +01:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
if (crossfadeWithThumb && animationNotReady) {
|
2022-08-12 17:23:51 +02:00
|
|
|
drawDrawable(canvas, drawable, (int) (overrideAlpha * 255), shaderToUse, orientation, backgroundThreadDrawHolder);
|
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;
|
2022-02-03 23:18:58 +01:00
|
|
|
if (useRoundForThumb && thumbShader == null) {
|
|
|
|
updateDrawableRadius(staticThumbDrawable);
|
2022-08-12 17:23:51 +02:00
|
|
|
thumbShader = this.thumbShader;
|
2022-02-03 23:18:58 +01:00
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
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;
|
2022-02-03 23:18:58 +01:00
|
|
|
if (useRoundForThumb && thumbShader == null) {
|
|
|
|
updateDrawableRadius(staticThumbDrawable);
|
2022-08-12 17:23:51 +02:00
|
|
|
thumbShader = this.thumbShader;
|
2022-02-03 23:18:58 +01:00
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
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) {
|
2020-12-23 08:48:30 +01:00
|
|
|
int alpha;
|
2021-09-20 07:54:41 +02:00
|
|
|
if (thumbDrawable instanceof SvgHelper.SvgDrawable || thumbDrawable instanceof Emoji.EmojiDrawable) {
|
2022-11-06 02:16:18 +01:00
|
|
|
alpha = (int) (overrideAlpha * (1.0f - currentAlpha) * 255);
|
2020-12-23 08:48:30 +01:00
|
|
|
} else {
|
2022-01-10 03:27:47 +01:00
|
|
|
alpha = (int) (overrideAlpha * previousAlpha * 255);
|
2020-12-23 08:48:30 +01:00
|
|
|
}
|
2022-08-12 17:23:51 +02:00
|
|
|
drawDrawable(canvas, thumbDrawable, alpha, thumbShaderToUse, thumbOrientation, backgroundThreadDrawHolder);
|
2021-09-20 07:54:41 +02:00
|
|
|
if (alpha != 255 && thumbDrawable instanceof Emoji.EmojiDrawable) {
|
|
|
|
thumbDrawable.setAlpha(255);
|
|
|
|
}
|
2014-10-01 21:55:24 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2022-11-06 02:16:18 +01:00
|
|
|
boolean restore = false;
|
|
|
|
if (crossfadeByScale > 0 && currentAlpha < 1 && crossfadingWithThumb) {
|
|
|
|
canvas.save();
|
|
|
|
restore = true;
|
|
|
|
roundPath.rewind();
|
|
|
|
AndroidUtilities.rectTmp.set(imageX, imageY, imageX + imageW, imageY + imageH);
|
|
|
|
for (int a = 0; a < roundRadius.length; a++) {
|
|
|
|
radii[a * 2] = roundRadius[a];
|
|
|
|
radii[a * 2 + 1] = roundRadius[a];
|
|
|
|
}
|
|
|
|
roundPath.addRoundRect(AndroidUtilities.rectTmp, radii, Path.Direction.CW);
|
|
|
|
canvas.clipPath(roundPath);
|
|
|
|
float s = 1f + crossfadeByScale * (1f - CubicBezierInterpolator.EASE_IN.getInterpolation(crossfadeProgress));
|
|
|
|
canvas.scale(s, s, getCenterX(), getCenterY());
|
|
|
|
}
|
2022-08-12 17:23:51 +02:00
|
|
|
drawDrawable(canvas, drawable, (int) (overrideAlpha * currentAlpha * 255), shaderToUse, orientation, backgroundThreadDrawHolder);
|
2022-11-06 02:16:18 +01:00
|
|
|
if (restore) {
|
|
|
|
canvas.restore();
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} else {
|
2022-08-12 17:23:51 +02:00
|
|
|
drawDrawable(canvas, drawable, (int) (overrideAlpha * 255), shaderToUse, orientation, backgroundThreadDrawHolder);
|
2014-05-17 01:05:49 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2022-09-16 20:48:21 +02:00
|
|
|
checkAlphaAnimation(animationNotReady && crossfadeWithThumb, backgroundThreadDrawHolder);
|
2021-06-25 02:43:10 +02:00
|
|
|
result = true;
|
2019-03-03 21:40:48 +01:00
|
|
|
} else if (staticThumbDrawable != null) {
|
2022-08-12 17:23:51 +02:00
|
|
|
drawDrawable(canvas, staticThumbDrawable, (int) (overrideAlpha * 255), null, thumbOrientation, backgroundThreadDrawHolder);
|
2022-09-16 20:48:21 +02:00
|
|
|
checkAlphaAnimation(animationNotReady, backgroundThreadDrawHolder);
|
2021-06-25 02:43:10 +02:00
|
|
|
result = true;
|
2016-01-11 18:19:48 +01:00
|
|
|
} else {
|
2022-09-16 20:48:21 +02:00
|
|
|
checkAlphaAnimation(animationNotReady, backgroundThreadDrawHolder);
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
2022-02-01 14:00:45 +01:00
|
|
|
|
2022-08-12 17:23:51 +02:00
|
|
|
if (drawable == null && animationNotReady && !drawInBackground) {
|
|
|
|
invalidate();
|
2022-02-01 14:00:45 +01:00
|
|
|
}
|
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
|
|
|
}
|
2021-06-25 02:43:10 +02:00
|
|
|
if (gradientBitmap != null && currentImageKey != null) {
|
|
|
|
canvas.restore();
|
|
|
|
}
|
|
|
|
return result;
|
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;
|
|
|
|
}
|
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
@Keep
|
2017-07-08 18:32:04 +02:00
|
|
|
public float getCurrentAlpha() {
|
|
|
|
return currentAlpha;
|
|
|
|
}
|
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
@Keep
|
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-07-18 15:01:39 +02:00
|
|
|
RLottieDrawable lottieDrawable = getLottieAnimation();
|
|
|
|
if (lottieDrawable != null && lottieDrawable.hasBitmap()) {
|
|
|
|
return lottieDrawable.getAnimatedBitmap();
|
2022-04-16 16:43:17 +02:00
|
|
|
}
|
|
|
|
AnimatedFileDrawable animation = getAnimation();
|
|
|
|
if (animation != null && animation.hasBitmap()) {
|
2019-03-03 21:40:48 +01:00
|
|
|
return animation.getAnimatedBitmap();
|
2019-07-18 15:01:39 +02:00
|
|
|
} else if (currentMediaDrawable instanceof BitmapDrawable && !(currentMediaDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
|
2019-03-03 21:40:48 +01:00
|
|
|
return ((BitmapDrawable) currentMediaDrawable).getBitmap();
|
2019-07-18 15:01:39 +02:00
|
|
|
} else if (currentImageDrawable instanceof BitmapDrawable && !(currentImageDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
|
2019-03-03 21:40:48 +01:00
|
|
|
return ((BitmapDrawable) currentImageDrawable).getBitmap();
|
2019-07-18 15:01:39 +02:00
|
|
|
} else if (currentThumbDrawable instanceof BitmapDrawable && !(currentThumbDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
|
2019-03-03 21:40:48 +01:00
|
|
|
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();
|
2019-07-18 15:01:39 +02:00
|
|
|
RLottieDrawable lottieDrawable = getLottieAnimation();
|
2020-07-26 10:03:38 +02:00
|
|
|
int orientation = 0;
|
2019-07-18 15:01:39 +02:00
|
|
|
if (lottieDrawable != null && lottieDrawable.hasBitmap()) {
|
|
|
|
bitmap = lottieDrawable.getAnimatedBitmap();
|
|
|
|
} else if (animation != null && animation.hasBitmap()) {
|
2019-03-03 21:40:48 +01:00
|
|
|
bitmap = animation.getAnimatedBitmap();
|
2020-07-26 10:03:38 +02:00
|
|
|
orientation = animation.getOrientation();
|
|
|
|
if (orientation != 0) {
|
|
|
|
return new BitmapHolder(Bitmap.createBitmap(bitmap), null, orientation);
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
} else if (currentMediaDrawable instanceof BitmapDrawable && !(currentMediaDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
|
2019-03-03 21:40:48 +01:00
|
|
|
bitmap = ((BitmapDrawable) currentMediaDrawable).getBitmap();
|
|
|
|
key = currentMediaKey;
|
2019-07-18 15:01:39 +02:00
|
|
|
} else if (currentImageDrawable instanceof BitmapDrawable && !(currentImageDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
|
2019-03-03 21:40:48 +01:00
|
|
|
bitmap = ((BitmapDrawable) currentImageDrawable).getBitmap();
|
|
|
|
key = currentImageKey;
|
2019-07-18 15:01:39 +02:00
|
|
|
} else if (currentThumbDrawable instanceof BitmapDrawable && !(currentThumbDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
|
2019-03-03 21:40:48 +01:00
|
|
|
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) {
|
2020-07-26 10:03:38 +02:00
|
|
|
return new BitmapHolder(bitmap, key, orientation);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public BitmapHolder getDrawableSafe() {
|
|
|
|
Drawable drawable = null;
|
|
|
|
String key = null;
|
|
|
|
if (currentMediaDrawable instanceof BitmapDrawable && !(currentMediaDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
|
|
|
|
drawable = currentMediaDrawable;
|
|
|
|
key = currentMediaKey;
|
|
|
|
} else if (currentImageDrawable instanceof BitmapDrawable && !(currentImageDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
|
|
|
|
drawable = currentImageDrawable;
|
|
|
|
key = currentImageKey;
|
|
|
|
} else if (currentThumbDrawable instanceof BitmapDrawable && !(currentThumbDrawable instanceof AnimatedFileDrawable) && !(currentMediaDrawable instanceof RLottieDrawable)) {
|
|
|
|
drawable = currentThumbDrawable;
|
|
|
|
key = currentThumbKey;
|
|
|
|
} else if (staticThumbDrawable instanceof BitmapDrawable) {
|
|
|
|
drawable = staticThumbDrawable;
|
|
|
|
}
|
|
|
|
if (drawable != null) {
|
|
|
|
return new BitmapHolder(drawable, key, 0);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-11-06 02:16:18 +01:00
|
|
|
public Drawable getThumb() {
|
|
|
|
return currentThumbDrawable;
|
|
|
|
}
|
|
|
|
|
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) {
|
2020-07-26 10:03:38 +02:00
|
|
|
return new BitmapHolder(bitmap, key, 0);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-02-26 02:32:51 +01:00
|
|
|
public int getBitmapWidth() {
|
2019-05-14 14:08:05 +02:00
|
|
|
Drawable drawable = getDrawable();
|
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
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
RLottieDrawable lottieDrawable = getLottieAnimation();
|
|
|
|
if (lottieDrawable != null) {
|
|
|
|
return lottieDrawable.getIntrinsicWidth();
|
|
|
|
}
|
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-05-14 14:08:05 +02:00
|
|
|
Drawable drawable = getDrawable();
|
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
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
RLottieDrawable lottieDrawable = getLottieAnimation();
|
|
|
|
if (lottieDrawable != null) {
|
|
|
|
return lottieDrawable.getIntrinsicHeight();
|
|
|
|
}
|
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;
|
2020-12-23 08:48:30 +01:00
|
|
|
if (invalidate) {
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void invalidate() {
|
|
|
|
if (parentView == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (invalidateAll) {
|
|
|
|
parentView.invalidate();
|
|
|
|
} else {
|
|
|
|
parentView.invalidate((int) imageX, (int) imageY, (int) (imageX + imageW), (int) (imageY + imageH));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void getParentPosition(int[] position) {
|
|
|
|
if (parentView == null) {
|
|
|
|
return;
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
2020-12-23 08:48:30 +01:00
|
|
|
parentView.getLocationInWindow(position);
|
2014-06-07 01:35:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getVisible() {
|
|
|
|
return isVisible;
|
|
|
|
}
|
2014-06-11 01:05:54 +02:00
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
@Keep
|
2015-01-02 23:15:07 +01:00
|
|
|
public void setAlpha(float value) {
|
2015-05-03 13:48:36 +02:00
|
|
|
overrideAlpha = value;
|
|
|
|
}
|
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
@Keep
|
|
|
|
public float getAlpha() {
|
|
|
|
return overrideAlpha;
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-11-06 02:16:18 +01:00
|
|
|
public boolean hasImageLoaded() {
|
|
|
|
return currentImageDrawable != null || currentMediaDrawable != null;
|
|
|
|
}
|
|
|
|
|
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) {
|
2022-08-12 17:23:51 +02:00
|
|
|
View oldParent = parentView;
|
2014-08-22 16:24:33 +02:00
|
|
|
parentView = view;
|
2019-03-03 21:40:48 +01:00
|
|
|
AnimatedFileDrawable animation = getAnimation();
|
2022-08-12 17:23:51 +02:00
|
|
|
if (animation != null && attachedToWindow) {
|
2019-03-03 21:40:48 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-09-30 15:48:47 +02:00
|
|
|
public void setImageY(float y) {
|
2017-03-31 01:58:05 +02:00
|
|
|
imageY = y;
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public void setImageWidth(int width) {
|
|
|
|
imageW = width;
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
public void setImageCoords(float x, float y, float width, float height) {
|
2014-08-22 16:24:33 +02:00
|
|
|
imageX = x;
|
|
|
|
imageY = y;
|
|
|
|
imageW = width;
|
|
|
|
imageH = height;
|
|
|
|
}
|
|
|
|
|
2022-06-21 04:51:00 +02:00
|
|
|
public void setImageCoords(Rect bounds) {
|
|
|
|
if (bounds != null) {
|
|
|
|
imageX = bounds.left;
|
|
|
|
imageY = bounds.top;
|
|
|
|
imageW = bounds.width();
|
|
|
|
imageH = bounds.height();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
public void setSideClip(float value) {
|
|
|
|
sideClip = value;
|
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
public float getCenterX() {
|
|
|
|
return imageX + imageW / 2.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
public float getCenterY() {
|
|
|
|
return imageY + imageH / 2.0f;
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
public float getImageX() {
|
2014-08-22 16:24:33 +02:00
|
|
|
return imageX;
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
public float getImageX2() {
|
2015-04-09 20:00:14 +02:00
|
|
|
return imageX + imageW;
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
public float getImageY() {
|
2014-08-22 16:24:33 +02:00
|
|
|
return imageY;
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
public float getImageY2() {
|
2015-04-09 20:00:14 +02:00
|
|
|
return imageY + imageH;
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
public float getImageWidth() {
|
2014-08-22 16:24:33 +02:00
|
|
|
return imageW;
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
public float getImageHeight() {
|
2014-08-22 16:24:33 +02:00
|
|
|
return imageH;
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public float getImageAspectRatio() {
|
2019-05-14 14:08:05 +02:00
|
|
|
return imageOrientation % 180 != 0 ? drawRegion.height() / drawRegion.width() : drawRegion.width() / 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;
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
public RectF getDrawRegion() {
|
2014-08-22 16:24:33 +02:00
|
|
|
return drawRegion;
|
|
|
|
}
|
|
|
|
|
2019-07-18 15:01:39 +02:00
|
|
|
public int getNewGuid() {
|
|
|
|
return ++currentGuid;
|
|
|
|
}
|
|
|
|
|
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 getMediaKey() {
|
|
|
|
return currentMediaKey;
|
|
|
|
}
|
|
|
|
|
2015-02-01 19:51:02 +01:00
|
|
|
public String getThumbKey() {
|
|
|
|
return currentThumbKey;
|
|
|
|
}
|
|
|
|
|
2022-06-21 04:51:00 +02:00
|
|
|
public long getSize() {
|
2015-02-01 19:51:02 +01:00
|
|
|
return currentSize;
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
public ImageLocation getMediaLocation() {
|
2019-03-03 21:40:48 +01:00
|
|
|
return currentMediaLocation;
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
public ImageLocation getImageLocation() {
|
2015-02-01 19:51:02 +01:00
|
|
|
return currentImageLocation;
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
public ImageLocation getThumbLocation() {
|
2015-02-01 19:51:02 +01:00
|
|
|
return currentThumbLocation;
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
public String getMediaFilter() {
|
|
|
|
return currentMediaFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getImageFilter() {
|
|
|
|
return currentImageFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getThumbFilter() {
|
|
|
|
return currentThumbFilter;
|
|
|
|
}
|
|
|
|
|
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) {
|
2020-01-23 07:15:40 +01:00
|
|
|
setRoundRadius(new int[]{value, value, value, value});
|
|
|
|
}
|
|
|
|
|
2022-03-11 17:49:54 +01:00
|
|
|
public void setRoundRadius(int tl, int tr, int br, int bl) {
|
|
|
|
setRoundRadius(new int[]{tl, tr, br, bl});
|
2020-01-23 07:15:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setRoundRadius(int[] value) {
|
|
|
|
boolean changed = false;
|
2020-06-04 18:47:15 +02:00
|
|
|
int firstValue = value[0];
|
|
|
|
isRoundRect = true;
|
2020-01-23 07:15:40 +01:00
|
|
|
for (int a = 0; a < roundRadius.length; a++) {
|
|
|
|
if (roundRadius[a] != value[a]) {
|
|
|
|
changed = true;
|
|
|
|
}
|
2020-06-04 18:47:15 +02:00
|
|
|
if (firstValue != value[a]) {
|
|
|
|
isRoundRect = false;
|
|
|
|
}
|
|
|
|
roundRadius[a] = value[a];
|
2020-01-23 07:15:40 +01:00
|
|
|
}
|
|
|
|
if (changed) {
|
2019-12-31 14:08:08 +01:00
|
|
|
if (currentImageDrawable != null && imageShader == null) {
|
|
|
|
updateDrawableRadius(currentImageDrawable);
|
|
|
|
}
|
|
|
|
if (currentMediaDrawable != null && mediaShader == null) {
|
|
|
|
updateDrawableRadius(currentMediaDrawable);
|
|
|
|
}
|
2022-02-03 23:18:58 +01:00
|
|
|
if (currentThumbDrawable != null) {
|
|
|
|
updateDrawableRadius(currentThumbDrawable);
|
2022-11-05 13:34:47 +01:00
|
|
|
}
|
|
|
|
if (staticThumbDrawable != null) {
|
2022-02-03 23:18:58 +01:00
|
|
|
updateDrawableRadius(staticThumbDrawable);
|
2019-12-31 14:08:08 +01:00
|
|
|
}
|
|
|
|
}
|
2014-10-21 22:35:16 +02:00
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public void setCurrentAccount(int value) {
|
|
|
|
currentAccount = value;
|
|
|
|
}
|
|
|
|
|
2020-01-23 07:15:40 +01:00
|
|
|
public int[] getRoundRadius() {
|
2014-11-17 03:44:57 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-06-21 04:51:00 +02:00
|
|
|
public TLRPC.Document getQualityThumbDocument() {
|
2019-03-03 21:40:48 +01:00
|
|
|
return qulityThumbDocument;
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public void setCrossfadeWithOldImage(boolean value) {
|
|
|
|
crossfadeWithOldImage = value;
|
|
|
|
}
|
|
|
|
|
2022-11-06 02:16:18 +01:00
|
|
|
public boolean isCrossfadingWithOldImage() {
|
|
|
|
return crossfadeWithOldImage && crossfadeImage != null && !crossfadingWithThumb;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-08-12 17:23:51 +02:00
|
|
|
public void setAllowLottieVibration(boolean allow) {
|
|
|
|
allowLottieVibration = allow;
|
|
|
|
}
|
|
|
|
|
2020-07-26 10:03:38 +02:00
|
|
|
public boolean getAllowStartAnimation() {
|
|
|
|
return allowStartAnimation;
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
public void setAllowStartLottieAnimation(boolean value) {
|
|
|
|
allowStartLottieAnimation = value;
|
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
public void setAllowDecodeSingleFrame(boolean value) {
|
|
|
|
allowDecodeSingleFrame = value;
|
|
|
|
}
|
|
|
|
|
2019-08-22 01:53:26 +02:00
|
|
|
public void setAutoRepeat(int value) {
|
|
|
|
autoRepeat = value;
|
|
|
|
RLottieDrawable drawable = getLottieAnimation();
|
|
|
|
if (drawable != null) {
|
|
|
|
drawable.setAutoRepeat(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-16 20:48:21 +02:00
|
|
|
public void setAutoRepeatCount(int count) {
|
|
|
|
autoRepeatCount = count;
|
|
|
|
if (getLottieAnimation() != null) {
|
|
|
|
getLottieAnimation().setAutoRepeatCount(count);
|
|
|
|
} else {
|
|
|
|
animatedFileDrawableRepeatMaxCount = count;
|
|
|
|
if (getAnimation() != null) {
|
|
|
|
getAnimation().repeatCount = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-12 17:23:51 +02:00
|
|
|
public void setAutoRepeatTimeout(long timeout) {
|
|
|
|
autoRepeatTimeout = timeout;
|
|
|
|
RLottieDrawable drawable = getLottieAnimation();
|
|
|
|
if (drawable != null) {
|
|
|
|
drawable.setAutoRepeatTimeout(autoRepeatTimeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
public void setUseSharedAnimationQueue(boolean value) {
|
|
|
|
useSharedAnimationQueue = 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) {
|
2019-05-14 14:08:05 +02:00
|
|
|
animation.setUseSharedQueue(useSharedAnimationQueue);
|
2019-03-03 21:40:48 +01:00
|
|
|
animation.start();
|
2020-09-30 15:48:47 +02:00
|
|
|
} else {
|
|
|
|
RLottieDrawable rLottieDrawable = getLottieAnimation();
|
|
|
|
if (rLottieDrawable != null && !rLottieDrawable.isRunning()) {
|
|
|
|
rLottieDrawable.restart();
|
|
|
|
}
|
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();
|
2020-09-30 15:48:47 +02:00
|
|
|
} else {
|
|
|
|
RLottieDrawable rLottieDrawable = getLottieAnimation();
|
|
|
|
if (rLottieDrawable != null && !rLottieDrawable.isRunning()) {
|
|
|
|
rLottieDrawable.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
|
|
|
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-07-18 15:01:39 +02:00
|
|
|
public RLottieDrawable getLottieAnimation() {
|
|
|
|
if (currentMediaDrawable instanceof RLottieDrawable) {
|
|
|
|
return (RLottieDrawable) currentMediaDrawable;
|
|
|
|
} else if (currentImageDrawable instanceof RLottieDrawable) {
|
|
|
|
return (RLottieDrawable) currentImageDrawable;
|
|
|
|
} else if (currentThumbDrawable instanceof RLottieDrawable) {
|
|
|
|
return (RLottieDrawable) currentThumbDrawable;
|
|
|
|
} else if (staticThumbDrawable instanceof RLottieDrawable) {
|
|
|
|
return (RLottieDrawable) staticThumbDrawable;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
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-07-18 15:01:39 +02:00
|
|
|
protected boolean setImageBitmapByKey(Drawable drawable, String key, int type, boolean memCache, int guid) {
|
|
|
|
if (drawable == null || key == null || currentGuid != guid) {
|
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;
|
|
|
|
}
|
2022-06-21 04:51:00 +02:00
|
|
|
boolean allowCrossFade = true;
|
2019-07-18 15:01:39 +02:00
|
|
|
if (!(drawable instanceof AnimatedFileDrawable)) {
|
2019-03-03 21:40:48 +01:00
|
|
|
ImageLoader.getInstance().incrementUseCount(currentImageKey);
|
2022-09-16 20:48:21 +02:00
|
|
|
if (videoThumbIsSame) {
|
|
|
|
allowCrossFade = drawable != currentImageDrawable && currentAlpha >= 1;
|
|
|
|
}
|
2020-06-04 18:47:15 +02:00
|
|
|
} else {
|
2022-02-01 14:00:45 +01:00
|
|
|
AnimatedFileDrawable animatedFileDrawable = (AnimatedFileDrawable) drawable;
|
|
|
|
animatedFileDrawable.setStartEndTime(startTime, endTime);
|
|
|
|
if (animatedFileDrawable.isWebmSticker) {
|
|
|
|
ImageLoader.getInstance().incrementUseCount(currentImageKey);
|
|
|
|
}
|
2022-06-21 04:51:00 +02:00
|
|
|
if (videoThumbIsSame) {
|
|
|
|
allowCrossFade = !animatedFileDrawable.hasBitmap();
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
currentImageDrawable = drawable;
|
2022-08-12 17:23:51 +02:00
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
if (drawable instanceof ExtendedBitmapDrawable) {
|
|
|
|
imageOrientation = ((ExtendedBitmapDrawable) drawable).getOrientation();
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
updateDrawableRadius(drawable);
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2022-06-21 04:51:00 +02:00
|
|
|
if (allowCrossFade && isVisible && (!memCache && !forcePreview || forceCrossfade) && crossfadeDuration != 0) {
|
|
|
|
boolean allowCrossfade = true;
|
2022-08-12 17:23:51 +02:00
|
|
|
if (currentMediaDrawable instanceof RLottieDrawable && ((RLottieDrawable) currentMediaDrawable).hasBitmap()) {
|
|
|
|
allowCrossfade = false;
|
|
|
|
} else if (currentMediaDrawable instanceof AnimatedFileDrawable && ((AnimatedFileDrawable) currentMediaDrawable).hasBitmap()) {
|
2022-06-21 04:51:00 +02:00
|
|
|
allowCrossfade = false;
|
2019-07-18 15:01:39 +02:00
|
|
|
} else if (currentImageDrawable instanceof RLottieDrawable) {
|
2022-06-21 04:51:00 +02:00
|
|
|
allowCrossfade = staticThumbDrawable instanceof LoadingStickerDrawable || staticThumbDrawable instanceof SvgHelper.SvgDrawable || staticThumbDrawable instanceof Emoji.EmojiDrawable;
|
2019-03-03 21:40:48 +01:00
|
|
|
}
|
2022-06-21 04:51:00 +02:00
|
|
|
if (allowCrossfade && (currentThumbDrawable != null || staticThumbDrawable != null || forceCrossfade)) {
|
2022-02-01 14:00:45 +01:00
|
|
|
if (currentThumbDrawable != null && staticThumbDrawable != null) {
|
|
|
|
previousAlpha = currentAlpha;
|
|
|
|
} else {
|
|
|
|
previousAlpha = 1f;
|
|
|
|
}
|
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;
|
2022-02-01 14:00:45 +01:00
|
|
|
previousAlpha = 1f;
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
} else if (type == TYPE_MEDIA) {
|
|
|
|
if (!key.equals(currentMediaKey)) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
if (!(drawable instanceof AnimatedFileDrawable)) {
|
2019-03-03 21:40:48 +01:00
|
|
|
ImageLoader.getInstance().incrementUseCount(currentMediaKey);
|
2020-06-04 18:47:15 +02:00
|
|
|
} else {
|
2022-02-01 14:00:45 +01:00
|
|
|
AnimatedFileDrawable animatedFileDrawable = (AnimatedFileDrawable) drawable;
|
|
|
|
animatedFileDrawable.setStartEndTime(startTime, endTime);
|
|
|
|
if (animatedFileDrawable.isWebmSticker) {
|
2022-06-21 04:51:00 +02:00
|
|
|
ImageLoader.getInstance().incrementUseCount(currentMediaKey);
|
|
|
|
}
|
|
|
|
if (videoThumbIsSame && (currentThumbDrawable instanceof AnimatedFileDrawable || currentImageDrawable instanceof AnimatedFileDrawable)) {
|
|
|
|
long currentTimestamp = 0;
|
|
|
|
if (currentThumbDrawable instanceof AnimatedFileDrawable) {
|
|
|
|
currentTimestamp = ((AnimatedFileDrawable) currentThumbDrawable).getLastFrameTimestamp();
|
|
|
|
}
|
|
|
|
animatedFileDrawable.seekTo(currentTimestamp, true, true);
|
2022-02-01 14:00:45 +01:00
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
currentMediaDrawable = drawable;
|
2019-12-31 14:08:08 +01:00
|
|
|
updateDrawableRadius(drawable);
|
2015-05-03 13:48:36 +02:00
|
|
|
|
2019-03-03 21:40:48 +01:00
|
|
|
if (currentImageDrawable == null) {
|
2022-08-12 17:23:51 +02:00
|
|
|
boolean allowCrossfade = true;
|
2019-03-03 21:40:48 +01:00
|
|
|
if (!memCache && !forcePreview || forceCrossfade) {
|
|
|
|
if (currentThumbDrawable == null && staticThumbDrawable == null || currentAlpha == 1.0f || forceCrossfade) {
|
2022-02-01 14:00:45 +01:00
|
|
|
if (currentThumbDrawable != null && staticThumbDrawable != null) {
|
|
|
|
previousAlpha = currentAlpha;
|
|
|
|
} else {
|
|
|
|
previousAlpha = 1f;
|
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
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;
|
2022-02-01 14:00:45 +01:00
|
|
|
previousAlpha = 1f;
|
2019-03-03 21:40:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} 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-05-14 14:08:05 +02:00
|
|
|
currentThumbDrawable = drawable;
|
|
|
|
if (drawable instanceof ExtendedBitmapDrawable) {
|
|
|
|
thumbOrientation = ((ExtendedBitmapDrawable) drawable).getOrientation();
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
2019-12-31 14:08:08 +01:00
|
|
|
updateDrawableRadius(drawable);
|
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;
|
2022-02-01 14:00:45 +01:00
|
|
|
previousAlpha = 1f;
|
2017-07-08 18:32:04 +02:00
|
|
|
} else {
|
|
|
|
currentAlpha = 0.0f;
|
2022-02-01 14:00:45 +01:00
|
|
|
previousAlpha = 1f;
|
2017-07-08 18:32:04 +02:00
|
|
|
lastUpdateAlphaTime = System.currentTimeMillis();
|
2022-01-10 03:27:47 +01:00
|
|
|
crossfadeWithThumb = staticThumbDrawable != null;
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
} else {
|
|
|
|
currentAlpha = 1.0f;
|
2022-02-01 14:00:45 +01:00
|
|
|
previousAlpha = 1f;
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
2019-03-03 21:40:48 +01:00
|
|
|
}
|
2020-03-30 14:00:09 +02:00
|
|
|
if (delegate != null) {
|
|
|
|
delegate.didSetImage(this, currentImageDrawable != null || currentThumbDrawable != null || staticThumbDrawable != null || currentMediaDrawable != null, currentImageDrawable == null && currentMediaDrawable == null, memCache);
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
if (drawable instanceof AnimatedFileDrawable) {
|
|
|
|
AnimatedFileDrawable fileDrawable = (AnimatedFileDrawable) drawable;
|
|
|
|
fileDrawable.setUseSharedQueue(useSharedAnimationQueue);
|
2022-02-03 23:18:58 +01:00
|
|
|
if (attachedToWindow) {
|
2022-06-21 04:51:00 +02:00
|
|
|
fileDrawable.addParent(this);
|
2022-02-03 23:18:58 +01:00
|
|
|
}
|
2021-06-25 02:43:10 +02:00
|
|
|
if (allowStartAnimation && currentOpenedLayerFlags == 0) {
|
2022-06-21 04:51:00 +02:00
|
|
|
fileDrawable.checkRepeat();
|
2019-03-03 21:40:48 +01:00
|
|
|
}
|
|
|
|
fileDrawable.setAllowDecodeSingleFrame(allowDecodeSingleFrame);
|
2019-08-22 01:53:26 +02:00
|
|
|
animationReadySent = false;
|
2022-02-01 14:00:45 +01:00
|
|
|
if (parentView != null) {
|
|
|
|
parentView.invalidate();
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
} else if (drawable instanceof RLottieDrawable) {
|
|
|
|
RLottieDrawable fileDrawable = (RLottieDrawable) drawable;
|
2022-08-12 17:23:51 +02:00
|
|
|
if (attachedToWindow) {
|
|
|
|
fileDrawable.addParentView(this);
|
|
|
|
}
|
2020-10-30 11:26:29 +01:00
|
|
|
if (allowStartLottieAnimation && (!fileDrawable.isHeavyDrawable() || currentOpenedLayerFlags == 0)) {
|
2019-07-18 15:01:39 +02:00
|
|
|
fileDrawable.start();
|
|
|
|
}
|
|
|
|
fileDrawable.setAllowDecodeSingleFrame(true);
|
2019-08-22 01:53:26 +02:00
|
|
|
fileDrawable.setAutoRepeat(autoRepeat);
|
2022-09-16 20:48:21 +02:00
|
|
|
fileDrawable.setAutoRepeatCount(autoRepeatCount);
|
2022-08-12 17:23:51 +02:00
|
|
|
fileDrawable.setAutoRepeatTimeout(autoRepeatTimeout);
|
2019-08-22 01:53:26 +02:00
|
|
|
animationReadySent = false;
|
2019-03-03 21:40:48 +01:00
|
|
|
}
|
2022-08-12 17:23:51 +02:00
|
|
|
invalidate();
|
2016-01-11 18:19:48 +01:00
|
|
|
return true;
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
public void setMediaStartEndTime(long startTime, long endTime) {
|
|
|
|
this.startTime = startTime;
|
|
|
|
this.endTime = endTime;
|
|
|
|
|
|
|
|
if (currentMediaDrawable instanceof AnimatedFileDrawable) {
|
|
|
|
((AnimatedFileDrawable) currentMediaDrawable).setStartEndTime(startTime, endTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2020-07-26 10:03:38 +02:00
|
|
|
if (key != null && (key.startsWith("-") || key.startsWith("strippedmessage-"))) {
|
2018-07-30 04:07:02 +02:00
|
|
|
String replacedKey = ImageLoader.getInstance().getReplacedKey(key);
|
|
|
|
if (replacedKey != null) {
|
|
|
|
key = replacedKey;
|
|
|
|
}
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
if (image instanceof RLottieDrawable) {
|
|
|
|
RLottieDrawable lottieDrawable = (RLottieDrawable) image;
|
2022-08-12 17:23:51 +02:00
|
|
|
lottieDrawable.removeParentView(this);
|
2019-07-18 15:01:39 +02:00
|
|
|
}
|
2022-02-03 23:18:58 +01:00
|
|
|
if (image instanceof AnimatedFileDrawable) {
|
2022-06-21 04:51:00 +02:00
|
|
|
AnimatedFileDrawable animatedFileDrawable = (AnimatedFileDrawable) image;
|
|
|
|
animatedFileDrawable.removeParent(this);
|
2022-02-03 23:18:58 +01:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
if (key != null && (newKey == null || !newKey.equals(key)) && image != null) {
|
2019-07-18 15:01:39 +02:00
|
|
|
if (image instanceof RLottieDrawable) {
|
|
|
|
RLottieDrawable fileDrawable = (RLottieDrawable) image;
|
|
|
|
boolean canDelete = ImageLoader.getInstance().decrementUseCount(key);
|
|
|
|
if (!ImageLoader.getInstance().isInMemCache(key, true)) {
|
|
|
|
if (canDelete) {
|
|
|
|
fileDrawable.recycle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (image instanceof AnimatedFileDrawable) {
|
2016-01-11 18:19:48 +01:00
|
|
|
AnimatedFileDrawable fileDrawable = (AnimatedFileDrawable) image;
|
2022-02-01 14:00:45 +01:00
|
|
|
if (fileDrawable.isWebmSticker) {
|
|
|
|
boolean canDelete = ImageLoader.getInstance().decrementUseCount(key);
|
|
|
|
if (!ImageLoader.getInstance().isInMemCache(key, true)) {
|
|
|
|
if (canDelete) {
|
|
|
|
fileDrawable.recycle();
|
|
|
|
}
|
|
|
|
} else if (canDelete) {
|
|
|
|
fileDrawable.stop();
|
|
|
|
}
|
|
|
|
} else {
|
2022-06-21 04:51:00 +02:00
|
|
|
if (fileDrawable.getParents().isEmpty()) {
|
|
|
|
fileDrawable.recycle();
|
|
|
|
}
|
2022-02-01 14:00:45 +01:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
} else if (image instanceof BitmapDrawable) {
|
|
|
|
Bitmap bitmap = ((BitmapDrawable) image).getBitmap();
|
|
|
|
boolean canDelete = ImageLoader.getInstance().decrementUseCount(key);
|
2019-07-18 15:01:39 +02:00
|
|
|
if (!ImageLoader.getInstance().isInMemCache(key, false)) {
|
2016-01-11 18:19:48 +01:00
|
|
|
if (canDelete) {
|
2022-06-21 04:51:00 +02:00
|
|
|
ArrayList<Bitmap> bitmapToRecycle = new ArrayList<>();
|
|
|
|
bitmapToRecycle.add(bitmap);
|
|
|
|
AndroidUtilities.recycleBitmaps(bitmapToRecycle);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
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;
|
2023-01-04 00:17:33 +01:00
|
|
|
mediaShader = null;
|
2019-03-03 21:40:48 +01:00
|
|
|
} else if (type == TYPE_CROSSFDADE) {
|
2017-12-08 18:35:59 +01:00
|
|
|
crossfadeKey = null;
|
|
|
|
crossfadeImage = null;
|
2023-01-04 00:17:33 +01:00
|
|
|
crossfadeShader = 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;
|
2023-01-04 00:17:33 +01:00
|
|
|
thumbShader = null;
|
2015-02-01 19:51:02 +01:00
|
|
|
} else {
|
2019-03-03 21:40:48 +01:00
|
|
|
currentImageDrawable = null;
|
|
|
|
currentImageKey = null;
|
2023-01-04 00:17:33 +01:00
|
|
|
imageShader = null;
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
public void setCrossfadeDuration(int duration) {
|
|
|
|
crossfadeDuration = duration;
|
|
|
|
}
|
|
|
|
|
2022-11-06 02:16:18 +01:00
|
|
|
public void setCrossfadeByScale(float value) {
|
|
|
|
crossfadeByScale = value;
|
|
|
|
}
|
|
|
|
|
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];
|
2019-05-14 14:08:05 +02:00
|
|
|
currentMediaLocation = (ImageLocation) args[2];
|
2019-03-03 21:40:48 +01:00
|
|
|
if (setImageBackup != null) {
|
2019-05-14 14:08:05 +02:00
|
|
|
setImageBackup.mediaLocation = (ImageLocation) args[2];
|
2019-03-03 21:40:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentImageKey != null && currentImageKey.equals(oldKey)) {
|
|
|
|
currentImageKey = (String) args[1];
|
2019-05-14 14:08:05 +02:00
|
|
|
currentImageLocation = (ImageLocation) args[2];
|
2019-03-03 21:40:48 +01:00
|
|
|
if (setImageBackup != null) {
|
2019-05-14 14:08:05 +02:00
|
|
|
setImageBackup.imageLocation = (ImageLocation) args[2];
|
2019-03-03 21:40:48 +01:00
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
if (currentThumbKey != null && currentThumbKey.equals(oldKey)) {
|
|
|
|
currentThumbKey = (String) args[1];
|
2019-05-14 14:08:05 +02:00
|
|
|
currentThumbLocation = (ImageLocation) args[2];
|
2019-03-03 21:40:48 +01:00
|
|
|
if (setImageBackup != null) {
|
2019-05-14 14:08:05 +02:00
|
|
|
setImageBackup.thumbLocation = (ImageLocation) args[2];
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
} else if (id == NotificationCenter.stopAllHeavyOperations) {
|
|
|
|
Integer layer = (Integer) args[0];
|
|
|
|
if (currentLayerNum >= layer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentOpenedLayerFlags |= layer;
|
|
|
|
if (currentOpenedLayerFlags != 0) {
|
|
|
|
RLottieDrawable lottieDrawable = getLottieAnimation();
|
2020-10-30 11:26:29 +01:00
|
|
|
if (lottieDrawable != null && lottieDrawable.isHeavyDrawable()) {
|
2019-07-18 15:01:39 +02:00
|
|
|
lottieDrawable.stop();
|
|
|
|
}
|
2021-06-25 02:43:10 +02:00
|
|
|
AnimatedFileDrawable animatedFileDrawable = getAnimation();
|
|
|
|
if (animatedFileDrawable != null) {
|
|
|
|
animatedFileDrawable.stop();
|
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
}
|
|
|
|
} else if (id == NotificationCenter.startAllHeavyOperations) {
|
|
|
|
Integer layer = (Integer) args[0];
|
|
|
|
if (currentLayerNum >= layer || currentOpenedLayerFlags == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2021-04-17 01:59:59 +02:00
|
|
|
currentOpenedLayerFlags &= ~layer;
|
2019-07-18 15:01:39 +02:00
|
|
|
if (currentOpenedLayerFlags == 0) {
|
|
|
|
RLottieDrawable lottieDrawable = getLottieAnimation();
|
2022-08-12 17:23:51 +02:00
|
|
|
if (lottieDrawable != null) {
|
|
|
|
lottieDrawable.setAllowVibration(allowLottieVibration);
|
|
|
|
}
|
2020-10-30 11:26:29 +01:00
|
|
|
if (allowStartLottieAnimation && lottieDrawable != null && lottieDrawable.isHeavyDrawable()) {
|
2019-07-18 15:01:39 +02:00
|
|
|
lottieDrawable.start();
|
|
|
|
}
|
2021-06-25 02:43:10 +02:00
|
|
|
AnimatedFileDrawable animatedFileDrawable = getAnimation();
|
|
|
|
if (allowStartAnimation && animatedFileDrawable != null) {
|
2022-06-21 04:51:00 +02:00
|
|
|
animatedFileDrawable.checkRepeat();
|
2022-08-12 17:23:51 +02:00
|
|
|
invalidate();
|
2021-06-25 02:43:10 +02:00
|
|
|
}
|
2019-07-18 15:01:39 +02:00
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
}
|
2021-07-30 16:49:55 +02:00
|
|
|
|
|
|
|
public void startCrossfadeFromStaticThumb(Bitmap thumb) {
|
2022-08-12 17:23:51 +02:00
|
|
|
startCrossfadeFromStaticThumb(new BitmapDrawable(null, thumb));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void startCrossfadeFromStaticThumb(Drawable thumb) {
|
2021-07-30 16:49:55 +02:00
|
|
|
currentThumbKey = null;
|
|
|
|
currentThumbDrawable = null;
|
|
|
|
thumbShader = null;
|
2022-02-12 06:22:45 +01:00
|
|
|
roundPaint.setShader(null);
|
2022-08-12 17:23:51 +02:00
|
|
|
staticThumbDrawable = thumb;
|
2021-07-30 16:49:55 +02:00
|
|
|
crossfadeWithThumb = true;
|
|
|
|
currentAlpha = 0f;
|
|
|
|
updateDrawableRadius(staticThumbDrawable);
|
|
|
|
}
|
2021-09-20 07:54:41 +02:00
|
|
|
|
|
|
|
public void setUniqKeyPrefix(String prefix) {
|
|
|
|
uniqKeyPrefix = prefix;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getUniqKeyPrefix() {
|
|
|
|
return uniqKeyPrefix;
|
|
|
|
}
|
2021-11-05 11:06:49 +01:00
|
|
|
|
|
|
|
public void addLoadingImageRunnable(Runnable loadOperationRunnable) {
|
|
|
|
loadingOperations.add(loadOperationRunnable);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ArrayList<Runnable> getLoadingOperations() {
|
|
|
|
return loadingOperations;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void moveImageToFront() {
|
|
|
|
ImageLoader.getInstance().moveToFront(currentImageKey);
|
|
|
|
ImageLoader.getInstance().moveToFront(currentThumbKey);
|
|
|
|
}
|
2022-06-21 04:51:00 +02:00
|
|
|
|
2022-09-16 20:48:21 +02:00
|
|
|
|
|
|
|
public void moveLottieToFront() {
|
|
|
|
BitmapDrawable drawable = null;
|
|
|
|
String key = null;
|
|
|
|
if (currentMediaDrawable instanceof RLottieDrawable) {
|
|
|
|
drawable = (BitmapDrawable) currentMediaDrawable;
|
|
|
|
key = currentMediaKey;
|
|
|
|
} else if (currentImageDrawable instanceof RLottieDrawable) {
|
|
|
|
drawable = (BitmapDrawable) currentImageDrawable;
|
|
|
|
key = currentImageKey;
|
|
|
|
}
|
|
|
|
if (key != null && drawable != null) {
|
|
|
|
ImageLoader.getInstance().moveToFront(key);
|
|
|
|
if (!ImageLoader.getInstance().isInMemCache(key, true)) {
|
|
|
|
ImageLoader.getInstance().getLottieMemCahce().put(key, drawable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-21 04:51:00 +02:00
|
|
|
public View getParentView() {
|
|
|
|
return parentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isAttachedToWindow() {
|
|
|
|
return attachedToWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setVideoThumbIsSame(boolean b) {
|
|
|
|
videoThumbIsSame = b;
|
|
|
|
}
|
|
|
|
|
2022-07-04 13:54:30 +02:00
|
|
|
public void setAllowLoadingOnAttachedOnly(boolean b) {
|
|
|
|
allowLoadingOnAttachedOnly = b;
|
|
|
|
}
|
|
|
|
|
2022-08-12 17:23:51 +02:00
|
|
|
public void setSkipUpdateFrame(boolean skipUpdateFrame) {
|
|
|
|
this.skipUpdateFrame = skipUpdateFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCurrentTime(long time) {
|
|
|
|
this.currentTime = time;
|
|
|
|
}
|
|
|
|
|
2022-09-16 20:48:21 +02:00
|
|
|
public void setFileLoadingPriority(int fileLoadingPriority) {
|
|
|
|
this.fileLoadingPriority = fileLoadingPriority;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getFileLoadingPriority() {
|
|
|
|
return fileLoadingPriority;
|
|
|
|
}
|
|
|
|
|
2022-11-12 09:41:35 +01:00
|
|
|
public BackgroundThreadDrawHolder setDrawInBackgroundThread(BackgroundThreadDrawHolder holder, int threadIndex) {
|
2022-08-12 17:23:51 +02:00
|
|
|
if (holder == null) {
|
|
|
|
holder = new BackgroundThreadDrawHolder();
|
|
|
|
}
|
2022-11-12 09:41:35 +01:00
|
|
|
holder.threadIndex = threadIndex;
|
2022-08-12 17:23:51 +02:00
|
|
|
holder.animation = getAnimation();
|
|
|
|
holder.lottieDrawable = getLottieAnimation();
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
holder.roundRadius[i] = roundRadius[i];
|
|
|
|
}
|
|
|
|
holder.mediaDrawable = currentMediaDrawable;
|
|
|
|
holder.mediaShader = mediaShader;
|
|
|
|
holder.imageDrawable = currentImageDrawable;
|
|
|
|
holder.imageShader = imageShader;
|
|
|
|
holder.thumbDrawable = currentThumbDrawable;
|
|
|
|
holder.thumbShader = thumbShader;
|
|
|
|
holder.staticThumbDrawable = staticThumbDrawable;
|
|
|
|
holder.crossfadeImage = crossfadeImage;
|
2022-09-16 20:48:21 +02:00
|
|
|
holder.colorFilter = colorFilter;
|
2022-08-12 17:23:51 +02:00
|
|
|
holder.crossfadingWithThumb = crossfadingWithThumb;
|
|
|
|
holder.crossfadeWithOldImage = crossfadeWithOldImage;
|
|
|
|
holder.currentAlpha = currentAlpha;
|
|
|
|
holder.previousAlpha = previousAlpha;
|
|
|
|
holder.crossfadeShader = crossfadeShader;
|
|
|
|
holder.animationNotReady = holder.animation != null && !holder.animation.hasBitmap() || holder.lottieDrawable != null && !holder.lottieDrawable.hasBitmap();
|
|
|
|
holder.imageX = imageX;
|
|
|
|
holder.imageY = imageY;
|
|
|
|
holder.imageW = imageW;
|
|
|
|
holder.imageH = imageH;
|
|
|
|
holder.overrideAlpha = overrideAlpha;
|
|
|
|
return holder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static class BackgroundThreadDrawHolder {
|
|
|
|
public boolean animationNotReady;
|
|
|
|
public float overrideAlpha;
|
|
|
|
public long time;
|
2022-11-12 09:41:35 +01:00
|
|
|
public int threadIndex;
|
2022-08-12 17:23:51 +02:00
|
|
|
private AnimatedFileDrawable animation;
|
|
|
|
private RLottieDrawable lottieDrawable;
|
|
|
|
private int[] roundRadius = new int[4];
|
|
|
|
private BitmapShader mediaShader;
|
|
|
|
private Drawable mediaDrawable;
|
|
|
|
private BitmapShader imageShader;
|
|
|
|
private Drawable imageDrawable;
|
|
|
|
private Drawable thumbDrawable;
|
|
|
|
private BitmapShader thumbShader;
|
|
|
|
private Drawable staticThumbDrawable;
|
|
|
|
private float currentAlpha;
|
|
|
|
private float previousAlpha;
|
|
|
|
private BitmapShader crossfadeShader;
|
|
|
|
public float imageH, imageW, imageX, imageY;
|
|
|
|
private boolean crossfadeWithOldImage;
|
|
|
|
private boolean crossfadingWithThumb;
|
|
|
|
private Drawable crossfadeImage;
|
|
|
|
public RectF drawRegion = new RectF();
|
2022-09-16 20:48:21 +02:00
|
|
|
public ColorFilter colorFilter;
|
2022-08-12 17:23:51 +02:00
|
|
|
Paint paint;
|
2022-09-16 20:48:21 +02:00
|
|
|
private Path roundPath;
|
2022-08-12 17:23:51 +02:00
|
|
|
|
|
|
|
public void release() {
|
|
|
|
animation = null;
|
|
|
|
lottieDrawable = null;
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
roundRadius[i] = roundRadius[i];
|
|
|
|
}
|
|
|
|
mediaDrawable = null;
|
|
|
|
mediaShader = null;
|
|
|
|
imageDrawable = null;
|
|
|
|
imageShader = null;
|
|
|
|
thumbDrawable = null;
|
|
|
|
thumbShader = null;
|
|
|
|
staticThumbDrawable = null;
|
|
|
|
crossfadeImage = null;
|
2022-09-16 20:48:21 +02:00
|
|
|
colorFilter = null;
|
2022-08-12 17:23:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setBounds(Rect bounds) {
|
|
|
|
if (bounds != null) {
|
|
|
|
imageX = bounds.left;
|
|
|
|
imageY = bounds.top;
|
|
|
|
imageW = bounds.width();
|
|
|
|
imageH = bounds.height();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void getBounds(RectF out) {
|
|
|
|
if (out != null) {
|
|
|
|
out.left = imageX;
|
|
|
|
out.top = imageY;
|
|
|
|
out.right = out.left + imageW;
|
|
|
|
out.bottom = out.top + imageH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void getBounds(Rect out) {
|
|
|
|
if (out != null) {
|
|
|
|
out.left = (int) imageX;
|
|
|
|
out.top = (int) imageY;
|
|
|
|
out.right = (int) (out.left + imageW);
|
|
|
|
out.bottom = (int) (out.top + imageH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-05 13:34:47 +01:00
|
|
|
|
|
|
|
public static class ReactionLastFrame extends BitmapDrawable {
|
|
|
|
|
|
|
|
public final static float LAST_FRAME_SCALE = 1.2f;
|
|
|
|
|
|
|
|
public ReactionLastFrame(Bitmap bitmap) {
|
|
|
|
super(bitmap);
|
|
|
|
}
|
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|