use of org.telegram.ui.Components.AnimatedFileDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class SendMessagesHelper method createVideoThumbnailAtTime.
public static Bitmap createVideoThumbnailAtTime(String filePath, long time, int[] orientation, boolean precise) {
Bitmap bitmap = null;
if (precise) {
AnimatedFileDrawable fileDrawable = new AnimatedFileDrawable(new File(filePath), true, 0, null, null, null, 0, 0, true);
bitmap = fileDrawable.getFrameAtTime(time, precise);
if (orientation != null) {
orientation[0] = fileDrawable.getOrientation();
}
fileDrawable.recycle();
if (bitmap == null) {
return createVideoThumbnailAtTime(filePath, time, orientation, false);
}
} else {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
try {
retriever.setDataSource(filePath);
bitmap = retriever.getFrameAtTime(time, MediaMetadataRetriever.OPTION_NEXT_SYNC);
if (bitmap == null) {
bitmap = retriever.getFrameAtTime(time, MediaMetadataRetriever.OPTION_CLOSEST);
}
} catch (Exception ignore) {
// Assume this is a corrupt video file.
} finally {
try {
retriever.release();
} catch (RuntimeException ex) {
// Ignore failures while cleaning up.
}
}
}
return bitmap;
}
use of org.telegram.ui.Components.AnimatedFileDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class ImageLoader method getFromLottieCahce.
private BitmapDrawable getFromLottieCahce(String imageKey) {
BitmapDrawable drawable = lottieMemCache.get(imageKey);
if (drawable instanceof AnimatedFileDrawable) {
if (((AnimatedFileDrawable) drawable).isRecycled()) {
lottieMemCache.remove(imageKey);
drawable = null;
}
}
return drawable;
}
use of org.telegram.ui.Components.AnimatedFileDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class ImageReceiver method onDetachedFromWindow.
public void onDetachedFromWindow() {
attachedToWindow = false;
if (currentImageLocation != null || currentMediaLocation != null || currentThumbLocation != null || staticThumbDrawable != null) {
if (setImageBackup == null) {
setImageBackup = new SetImageBackup();
}
setImageBackup.mediaLocation = currentMediaLocation;
setImageBackup.mediaFilter = currentMediaFilter;
setImageBackup.imageLocation = currentImageLocation;
setImageBackup.imageFilter = currentImageFilter;
setImageBackup.thumbLocation = currentThumbLocation;
setImageBackup.thumbFilter = currentThumbFilter;
setImageBackup.thumb = staticThumbDrawable;
setImageBackup.size = currentSize;
setImageBackup.ext = currentExt;
setImageBackup.cacheType = currentCacheType;
setImageBackup.parentObject = currentParentObject;
}
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didReplacedPhotoInMemCache);
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.stopAllHeavyOperations);
NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.startAllHeavyOperations);
if (staticThumbDrawable != null) {
staticThumbDrawable = null;
thumbShader = null;
roundPaint.setShader(null);
}
clearImage();
if (isPressed == 0) {
pressedProgress = 0f;
}
AnimatedFileDrawable animatedFileDrawable = getAnimation();
if (animatedFileDrawable != null) {
animatedFileDrawable.removeParent(parentView);
}
}
use of org.telegram.ui.Components.AnimatedFileDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class ImageReceiver method startAnimation.
public void startAnimation() {
AnimatedFileDrawable animation = getAnimation();
if (animation != null) {
animation.setUseSharedQueue(useSharedAnimationQueue);
animation.start();
} else {
RLottieDrawable rLottieDrawable = getLottieAnimation();
if (rLottieDrawable != null && !rLottieDrawable.isRunning()) {
rLottieDrawable.restart();
}
}
}
use of org.telegram.ui.Components.AnimatedFileDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class ImageReceiver method recycleBitmap.
private void recycleBitmap(String newKey, int type) {
String key;
Drawable image;
if (type == TYPE_MEDIA) {
key = currentMediaKey;
image = currentMediaDrawable;
} else if (type == TYPE_CROSSFDADE) {
key = crossfadeKey;
image = crossfadeImage;
} else if (type == TYPE_THUMB) {
key = currentThumbKey;
image = currentThumbDrawable;
} else {
key = currentImageKey;
image = currentImageDrawable;
}
if (key != null && (key.startsWith("-") || key.startsWith("strippedmessage-"))) {
String replacedKey = ImageLoader.getInstance().getReplacedKey(key);
if (replacedKey != null) {
key = replacedKey;
}
}
if (image instanceof RLottieDrawable) {
RLottieDrawable lottieDrawable = (RLottieDrawable) image;
lottieDrawable.removeParentView(parentView);
}
if (image instanceof AnimatedFileDrawable) {
AnimatedFileDrawable lottieDrawable = (AnimatedFileDrawable) image;
lottieDrawable.removeParent(parentView);
}
if (key != null && (newKey == null || !newKey.equals(key)) && image != null) {
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) {
AnimatedFileDrawable fileDrawable = (AnimatedFileDrawable) image;
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 {
fileDrawable.recycle();
}
} else if (image instanceof BitmapDrawable) {
Bitmap bitmap = ((BitmapDrawable) image).getBitmap();
boolean canDelete = ImageLoader.getInstance().decrementUseCount(key);
if (!ImageLoader.getInstance().isInMemCache(key, false)) {
if (canDelete) {
bitmap.recycle();
}
}
}
}
if (type == TYPE_MEDIA) {
currentMediaKey = null;
currentMediaDrawable = null;
} else if (type == TYPE_CROSSFDADE) {
crossfadeKey = null;
crossfadeImage = null;
} else if (type == TYPE_THUMB) {
currentThumbDrawable = null;
currentThumbKey = null;
} else {
currentImageDrawable = null;
currentImageKey = null;
}
}
Aggregations