use of org.telegram.messenger.ImageReceiver in project Telegram-FOSS by Telegram-FOSS-Team.
the class EmojiThemes method loadWallpaperThumb.
public void loadWallpaperThumb(int index, ResultCallback<Pair<Long, Bitmap>> callback) {
final TLRPC.WallPaper wallpaper = getWallpaper(index);
if (wallpaper == null) {
if (callback != null) {
callback.onComplete(null);
}
return;
}
long themeId = getTlTheme(index).id;
Bitmap bitmap = ChatThemeController.getWallpaperThumbBitmap(themeId);
File file = getWallpaperThumbFile(themeId);
if (bitmap == null && file.exists() && file.length() > 0) {
try {
bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
} catch (Exception e) {
FileLog.e(e);
}
}
if (bitmap != null) {
if (callback != null) {
callback.onComplete(new Pair<>(themeId, bitmap));
}
return;
}
if (wallpaper.document == null) {
if (callback != null) {
callback.onComplete(new Pair<>(themeId, null));
}
return;
}
final TLRPC.PhotoSize thumbSize = FileLoader.getClosestPhotoSizeWithSize(wallpaper.document.thumbs, 120);
ImageLocation imageLocation = ImageLocation.getForDocument(thumbSize, wallpaper.document);
ImageReceiver imageReceiver = new ImageReceiver();
imageReceiver.setImage(imageLocation, "120_80", null, null, null, 1);
imageReceiver.setDelegate((receiver, set, thumb, memCache) -> {
ImageReceiver.BitmapHolder holder = receiver.getBitmapSafe();
if (!set || holder == null) {
return;
}
Bitmap resultBitmap = holder.bitmap;
if (resultBitmap == null && (holder.drawable instanceof BitmapDrawable)) {
resultBitmap = ((BitmapDrawable) holder.drawable).getBitmap();
}
if (resultBitmap != null) {
if (callback != null) {
callback.onComplete(new Pair<>(themeId, resultBitmap));
}
final Bitmap saveBitmap = resultBitmap;
Utilities.globalQueue.postRunnable(() -> {
try (FileOutputStream outputStream = new FileOutputStream(file)) {
saveBitmap.compress(Bitmap.CompressFormat.PNG, 87, outputStream);
} catch (Exception e) {
FileLog.e(e);
}
});
} else {
if (callback != null) {
callback.onComplete(null);
}
}
});
ImageLoader.getInstance().loadImageForImageReceiver(imageReceiver);
}
use of org.telegram.messenger.ImageReceiver in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChannelAdminLogActivity method updateTextureViewPosition.
private void updateTextureViewPosition() {
boolean foundTextureViewMessage = false;
int count = chatListView.getChildCount();
for (int a = 0; a < count; a++) {
View view = chatListView.getChildAt(a);
if (view instanceof ChatMessageCell) {
ChatMessageCell messageCell = (ChatMessageCell) view;
MessageObject messageObject = messageCell.getMessageObject();
if (roundVideoContainer != null && messageObject.isRoundVideo() && MediaController.getInstance().isPlayingMessage(messageObject)) {
ImageReceiver imageReceiver = messageCell.getPhotoImage();
roundVideoContainer.setTranslationX(imageReceiver.getImageX());
roundVideoContainer.setTranslationY(fragmentView.getPaddingTop() + messageCell.getTop() + imageReceiver.getImageY());
fragmentView.invalidate();
roundVideoContainer.invalidate();
foundTextureViewMessage = true;
break;
}
}
}
if (roundVideoContainer != null) {
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if (!foundTextureViewMessage) {
roundVideoContainer.setTranslationY(-AndroidUtilities.roundMessageSize - 100);
fragmentView.invalidate();
if (messageObject != null && messageObject.isRoundVideo()) {
if (checkTextureViewPosition || PipRoundVideoView.getInstance() != null) {
MediaController.getInstance().setCurrentVideoVisible(false);
}
}
} else {
MediaController.getInstance().setCurrentVideoVisible(true);
}
}
}
use of org.telegram.messenger.ImageReceiver in project Telegram-FOSS by Telegram-FOSS-Team.
the class EmojiView method startStopVisibleGifs.
private void startStopVisibleGifs(boolean start) {
if (gifGridView == null) {
return;
}
int count = gifGridView.getChildCount();
for (int a = 0; a < count; a++) {
View child = gifGridView.getChildAt(a);
if (child instanceof ContextLinkCell) {
ContextLinkCell cell = (ContextLinkCell) child;
ImageReceiver imageReceiver = cell.getPhotoImage();
if (start) {
imageReceiver.setAllowStartAnimation(true);
imageReceiver.startAnimation();
} else {
imageReceiver.setAllowStartAnimation(false);
imageReceiver.stopAnimation();
}
}
}
}
use of org.telegram.messenger.ImageReceiver in project Telegram-FOSS by Telegram-FOSS-Team.
the class HintView method showForMessageCell.
public boolean showForMessageCell(ChatMessageCell cell, Object object, int x, int y, boolean animated) {
if (currentType == TYPE_POLL_VOTE && y == shownY && messageCell == cell || currentType != TYPE_POLL_VOTE && (currentType == 0 && getTag() != null || messageCell == cell)) {
return false;
}
if (hideRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(hideRunnable);
hideRunnable = null;
}
int[] position = new int[2];
cell.getLocationInWindow(position);
int top = position[1];
View p = (View) getParent();
p.getLocationInWindow(position);
top -= position[1];
View parentView = (View) cell.getParent();
int centerX;
if (currentType == 0) {
ImageReceiver imageReceiver = cell.getPhotoImage();
top += imageReceiver.getImageY();
int height = (int) imageReceiver.getImageHeight();
int bottom = top + height;
int parentHeight = parentView.getMeasuredHeight();
if (top <= getMeasuredHeight() + AndroidUtilities.dp(10) || bottom > parentHeight + height / 4) {
return false;
}
centerX = cell.getNoSoundIconCenterX();
} else if (currentType == TYPE_POLL_VOTE) {
Integer count = (Integer) object;
centerX = x;
top += y;
shownY = y;
if (count == -1) {
textView.setText(LocaleController.getString("PollSelectOption", R.string.PollSelectOption));
} else {
if (cell.getMessageObject().isQuiz()) {
if (count == 0) {
textView.setText(LocaleController.getString("NoVotesQuiz", R.string.NoVotesQuiz));
} else {
textView.setText(LocaleController.formatPluralString("Answer", count));
}
} else {
if (count == 0) {
textView.setText(LocaleController.getString("NoVotes", R.string.NoVotes));
} else {
textView.setText(LocaleController.formatPluralString("Vote", count));
}
}
}
measure(MeasureSpec.makeMeasureSpec(1000, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(1000, MeasureSpec.AT_MOST));
} else {
MessageObject messageObject = cell.getMessageObject();
if (overrideText == null) {
textView.setText(LocaleController.getString("HidAccount", R.string.HidAccount));
} else {
textView.setText(overrideText);
}
measure(MeasureSpec.makeMeasureSpec(1000, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(1000, MeasureSpec.AT_MOST));
TLRPC.User user = cell.getCurrentUser();
if (user != null && user.id == 0) {
top += (cell.getMeasuredHeight() - Math.max(0, cell.getBottom() - parentView.getMeasuredHeight()) - AndroidUtilities.dp(50));
} else {
top += AndroidUtilities.dp(22);
if (!messageObject.isOutOwner() && cell.isDrawNameLayout()) {
top += AndroidUtilities.dp(20);
}
}
if (!isTopArrow && top <= getMeasuredHeight() + AndroidUtilities.dp(10)) {
return false;
}
centerX = cell.getForwardNameCenterX();
}
int parentWidth = parentView.getMeasuredWidth();
if (isTopArrow) {
setTranslationY(extraTranslationY + (translationY = AndroidUtilities.dp(44)));
} else {
setTranslationY(extraTranslationY + (translationY = top - getMeasuredHeight()));
}
int iconX = cell.getLeft() + centerX;
int left = AndroidUtilities.dp(19);
if (currentType == TYPE_POLL_VOTE) {
int offset = Math.max(0, centerX - getMeasuredWidth() / 2 - AndroidUtilities.dp(19.1f));
setTranslationX(offset);
left += offset;
} else if (iconX > parentView.getMeasuredWidth() / 2) {
int offset = parentWidth - getMeasuredWidth() - AndroidUtilities.dp(38);
setTranslationX(offset);
left += offset;
} else {
setTranslationX(0);
}
float arrowX = cell.getLeft() + centerX - left - arrowImageView.getMeasuredWidth() / 2;
arrowImageView.setTranslationX(arrowX);
if (iconX > parentView.getMeasuredWidth() / 2) {
if (arrowX < AndroidUtilities.dp(10)) {
float diff = arrowX - AndroidUtilities.dp(10);
setTranslationX(getTranslationX() + diff);
arrowImageView.setTranslationX(arrowX - diff);
}
} else {
if (arrowX > getMeasuredWidth() - AndroidUtilities.dp(14 + 10)) {
float diff = arrowX - getMeasuredWidth() + AndroidUtilities.dp(14 + 10);
setTranslationX(diff);
arrowImageView.setTranslationX(arrowX - diff);
} else if (arrowX < AndroidUtilities.dp(10)) {
float diff = arrowX - AndroidUtilities.dp(10);
setTranslationX(getTranslationX() + diff);
arrowImageView.setTranslationX(arrowX - diff);
}
}
messageCell = cell;
if (animatorSet != null) {
animatorSet.cancel();
animatorSet = null;
}
setTag(1);
setVisibility(VISIBLE);
if (animated) {
animatorSet = new AnimatorSet();
animatorSet.playTogether(ObjectAnimator.ofFloat(this, View.ALPHA, 0.0f, 1.0f));
animatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
animatorSet = null;
AndroidUtilities.runOnUIThread(hideRunnable = () -> hide(), currentType == 0 ? 10000 : 2000);
}
});
animatorSet.setDuration(300);
animatorSet.start();
} else {
setAlpha(1.0f);
}
return true;
}
use of org.telegram.messenger.ImageReceiver in project Telegram-FOSS by Telegram-FOSS-Team.
the class GroupedPhotosListView method fillImages.
private void fillImages(boolean move, int dx) {
if (!move && !imagesToDraw.isEmpty()) {
unusedReceivers.addAll(imagesToDraw);
imagesToDraw.clear();
moving = false;
moveLineProgress = 1.0f;
currentItemProgress = 1.0f;
nextItemProgress = 0.0f;
}
invalidate();
if (getMeasuredWidth() == 0 || currentPhotos.isEmpty()) {
return;
}
int width = getMeasuredWidth();
int startX = getMeasuredWidth() / 2 - itemWidth / 2;
int addRightIndex;
int addLeftIndex;
if (move) {
addRightIndex = Integer.MIN_VALUE;
addLeftIndex = Integer.MAX_VALUE;
int count = imagesToDraw.size();
for (int a = 0; a < count; a++) {
ImageReceiver receiver = imagesToDraw.get(a);
int num = receiver.getParam();
int x = startX + (num - currentImage) * (itemWidth + itemSpacing) + dx;
if (x > width || x + itemWidth < 0) {
unusedReceivers.add(receiver);
imagesToDraw.remove(a);
count--;
a--;
}
addLeftIndex = Math.min(addLeftIndex, num - 1);
addRightIndex = Math.max(addRightIndex, num + 1);
}
} else {
addRightIndex = currentImage;
addLeftIndex = currentImage - 1;
}
if (addRightIndex != Integer.MIN_VALUE) {
int count = currentPhotos.size();
for (int a = addRightIndex; a < count; a++) {
int x = startX + (a - currentImage) * (itemWidth + itemSpacing) + dx;
if (x < width) {
ImageLocation location = currentPhotos.get(a);
ImageReceiver receiver = getFreeReceiver();
receiver.setImageCoords(x, itemY, itemWidth, itemHeight);
Object parent;
if (currentObjects.get(0) instanceof MessageObject) {
parent = currentObjects.get(a);
} else if (currentObjects.get(0) instanceof TLRPC.PageBlock) {
parent = delegate.getParentObject();
} else {
parent = "avatar_" + delegate.getAvatarsDialogId();
}
receiver.setImage(null, null, location, "80_80", 0, null, parent, 1);
receiver.setParam(a);
} else {
break;
}
}
}
if (addLeftIndex != Integer.MAX_VALUE) {
for (int a = addLeftIndex; a >= 0; a--) {
int x = startX + (a - currentImage) * (itemWidth + itemSpacing) + dx + itemWidth;
if (x > 0) {
ImageLocation location = currentPhotos.get(a);
ImageReceiver receiver = getFreeReceiver();
receiver.setImageCoords(x, itemY, itemWidth, itemHeight);
Object parent;
if (currentObjects.get(0) instanceof MessageObject) {
parent = currentObjects.get(a);
} else if (currentObjects.get(0) instanceof TLRPC.PageBlock) {
parent = delegate.getParentObject();
} else {
parent = "avatar_" + delegate.getAvatarsDialogId();
}
receiver.setImage(null, null, location, "80_80", 0, null, parent, 1);
receiver.setParam(a);
} else {
break;
}
}
}
if (showAnimator != null && !showAnimator.isStarted()) {
showAnimator.start();
}
}
Aggregations