use of org.telegram.messenger.ImageLocation in project Telegram-FOSS by Telegram-FOSS-Team.
the class AudioPlayerAlert method updateCover.
private void updateCover(MessageObject messageObject, boolean animated) {
final BackupImageView imageView = animated ? coverContainer.getNextImageView() : coverContainer.getImageView();
final AudioInfo audioInfo = MediaController.getInstance().getAudioInfo();
if (audioInfo != null && audioInfo.getCover() != null) {
imageView.setImageBitmap(audioInfo.getCover());
currentFile = null;
currentAudioFinishedLoading = true;
} else {
TLRPC.Document document = messageObject.getDocument();
currentFile = FileLoader.getAttachFileName(document);
currentAudioFinishedLoading = false;
String artworkUrl = messageObject.getArtworkUrl(false);
final ImageLocation thumbImageLocation = getArtworkThumbImageLocation(messageObject);
if (!TextUtils.isEmpty(artworkUrl)) {
imageView.setImage(ImageLocation.getForPath(artworkUrl), null, thumbImageLocation, null, null, 0, 1, messageObject);
} else if (thumbImageLocation != null) {
imageView.setImage(null, null, thumbImageLocation, null, null, 0, 1, messageObject);
} else {
imageView.setImageDrawable(null);
}
imageView.invalidate();
}
if (animated) {
coverContainer.switchImageViews();
}
}
use of org.telegram.messenger.ImageLocation 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.ImageLocation in project Telegram-FOSS by Telegram-FOSS-Team.
the class StickerSetCell method setStickersSet.
public void setStickersSet(TLRPC.TL_messages_stickerSet set, boolean divider) {
needDivider = divider;
stickersSet = set;
imageView.setVisibility(VISIBLE);
if (progressView != null) {
progressView.setVisibility(INVISIBLE);
}
textView.setTranslationY(0);
textView.setText(stickersSet.set.title);
if (stickersSet.set.archived) {
textView.setAlpha(0.5f);
valueTextView.setAlpha(0.5f);
imageView.setAlpha(0.5f);
} else {
textView.setAlpha(1.0f);
valueTextView.setAlpha(1.0f);
imageView.setAlpha(1.0f);
}
ArrayList<TLRPC.Document> documents = set.documents;
if (documents != null && !documents.isEmpty()) {
valueTextView.setText(LocaleController.formatPluralString("Stickers", documents.size()));
TLRPC.Document sticker = documents.get(0);
TLObject object = FileLoader.getClosestPhotoSizeWithSize(set.set.thumbs, 90);
if (object == null) {
object = sticker;
}
SvgHelper.SvgDrawable svgThumb = DocumentObject.getSvgThumb(set.set.thumbs, Theme.key_windowBackgroundGray, 1.0f);
ImageLocation imageLocation;
if (object instanceof TLRPC.Document) {
TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(sticker.thumbs, 90);
imageLocation = ImageLocation.getForDocument(thumb, sticker);
} else {
TLRPC.PhotoSize thumb = (TLRPC.PhotoSize) object;
imageLocation = ImageLocation.getForSticker(thumb, sticker, set.set.thumb_version);
}
if (object instanceof TLRPC.Document && MessageObject.isAnimatedStickerDocument(sticker, true) || MessageObject.isVideoSticker(sticker)) {
if (svgThumb != null) {
imageView.setImage(ImageLocation.getForDocument(sticker), "50_50", svgThumb, 0, set);
} else {
imageView.setImage(ImageLocation.getForDocument(sticker), "50_50", imageLocation, null, 0, set);
}
} else if (imageLocation != null && imageLocation.imageType == FileLoader.IMAGE_TYPE_LOTTIE) {
imageView.setImage(imageLocation, "50_50", "tgs", svgThumb, set);
} else {
imageView.setImage(imageLocation, "50_50", "webp", svgThumb, set);
}
} else {
valueTextView.setText(LocaleController.formatPluralString("Stickers", 0));
imageView.setImageDrawable(null);
}
}
use of org.telegram.messenger.ImageLocation in project Telegram-FOSS by Telegram-FOSS-Team.
the class ContactsEmptyView method setSticker.
private void setSticker() {
TLRPC.TL_messages_stickerSet set = MediaDataController.getInstance(currentAccount).getStickerSetByName(stickerSetName);
if (set == null) {
set = MediaDataController.getInstance(currentAccount).getStickerSetByEmojiOrName(stickerSetName);
}
if (set != null && set.documents.size() >= 1) {
TLRPC.Document document = set.documents.get(0);
ImageLocation imageLocation = ImageLocation.getForDocument(document);
stickerView.setImage(imageLocation, "130_130", "tgs", drawable, set);
} else {
MediaDataController.getInstance(currentAccount).loadStickersByEmojiOrName(stickerSetName, false, true);
stickerView.setImageDrawable(drawable);
}
}
use of org.telegram.messenger.ImageLocation in project Telegram-FOSS by Telegram-FOSS-Team.
the class MediaActivity method createView.
@Override
public View createView(Context context) {
actionBar.setBackButtonDrawable(new BackDrawable(false));
actionBar.setCastShadows(false);
actionBar.setAddToContainer(false);
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
FrameLayout avatarContainer = new FrameLayout(context);
FrameLayout fragmentView = new FrameLayout(context) {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
FrameLayout.LayoutParams lp = (LayoutParams) sharedMediaLayout.getLayoutParams();
lp.topMargin = ActionBar.getCurrentActionBarHeight() + (actionBar.getOccupyStatusBar() ? AndroidUtilities.statusBarHeight : 0);
lp = (LayoutParams) avatarContainer.getLayoutParams();
lp.topMargin = actionBar.getOccupyStatusBar() ? AndroidUtilities.statusBarHeight : 0;
lp.height = ActionBar.getCurrentActionBarHeight();
int textTop = (ActionBar.getCurrentActionBarHeight() / 2 - AndroidUtilities.dp(22)) / 2 + AndroidUtilities.dp(!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? 4 : 5);
lp = (LayoutParams) nameTextView.getLayoutParams();
lp.topMargin = textTop;
textTop = ActionBar.getCurrentActionBarHeight() / 2 + (ActionBar.getCurrentActionBarHeight() / 2 - AndroidUtilities.dp(19)) / 2 - AndroidUtilities.dp(3);
lp = (LayoutParams) mediaCounterTextView.getLayoutParams();
lp.topMargin = textTop;
lp = (LayoutParams) avatarImageView.getLayoutParams();
lp.topMargin = (ActionBar.getCurrentActionBarHeight() - AndroidUtilities.dp(42)) / 2;
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (sharedMediaLayout != null && sharedMediaLayout.isInFastScroll()) {
return sharedMediaLayout.dispatchFastScrollEvent(ev);
}
if (sharedMediaLayout != null && sharedMediaLayout.checkPinchToZoom(ev)) {
return true;
}
return super.dispatchTouchEvent(ev);
}
};
this.fragmentView = fragmentView;
nameTextView = new SimpleTextView(context);
nameTextView.setTextSize(18);
nameTextView.setGravity(Gravity.LEFT);
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
nameTextView.setLeftDrawableTopPadding(-AndroidUtilities.dp(1.3f));
nameTextView.setScrollNonFitText(true);
nameTextView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
avatarContainer.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 118, 0, 56, 0));
avatarImageView = new ProfileActivity.AvatarImageView(context) {
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
if (getImageReceiver().hasNotThumb()) {
info.setText(LocaleController.getString("AccDescrProfilePicture", R.string.AccDescrProfilePicture));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(AccessibilityNodeInfo.ACTION_CLICK, LocaleController.getString("Open", R.string.Open)));
info.addAction(new AccessibilityNodeInfo.AccessibilityAction(AccessibilityNodeInfo.ACTION_LONG_CLICK, LocaleController.getString("AccDescrOpenInPhotoViewer", R.string.AccDescrOpenInPhotoViewer)));
}
} else {
info.setVisibleToUser(false);
}
}
};
avatarImageView.getImageReceiver().setAllowDecodeSingleFrame(true);
avatarImageView.setRoundRadius(AndroidUtilities.dp(21));
avatarImageView.setPivotX(0);
avatarImageView.setPivotY(0);
AvatarDrawable avatarDrawable = new AvatarDrawable();
avatarDrawable.setProfile(true);
avatarImageView.setImageDrawable(avatarDrawable);
avatarContainer.addView(avatarImageView, LayoutHelper.createFrame(42, 42, Gravity.TOP | Gravity.LEFT, 64, 0, 0, 0));
mediaCounterTextView = new AudioPlayerAlert.ClippingTextViewSwitcher(context) {
@Override
protected TextView createTextView() {
TextView textView = new TextView(context);
textView.setTextColor(Theme.getColor(Theme.key_player_actionBarSubtitle));
textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
textView.setSingleLine(true);
textView.setEllipsize(TextUtils.TruncateAt.END);
textView.setGravity(Gravity.LEFT);
return textView;
}
};
avatarContainer.addView(mediaCounterTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 118, 0, 56, 0));
sharedMediaLayout = new SharedMediaLayout(context, dialogId, sharedMediaPreloader, 0, null, currentChatInfo, false, this, new SharedMediaLayout.Delegate() {
@Override
public void scrollToSharedMedia() {
}
@Override
public boolean onMemberClick(TLRPC.ChatParticipant participant, boolean b, boolean resultOnly) {
return false;
}
@Override
public TLRPC.Chat getCurrentChat() {
return null;
}
@Override
public boolean isFragmentOpened() {
return true;
}
@Override
public RecyclerListView getListView() {
return null;
}
@Override
public boolean canSearchMembers() {
return false;
}
@Override
public void updateSelectedMediaTabText() {
updateMediaCount();
}
}, SharedMediaLayout.VIEW_TYPE_MEDIA_ACTIVITY) {
@Override
protected void onSelectedTabChanged() {
updateMediaCount();
}
@Override
protected void onSearchStateChanged(boolean expanded) {
if (SharedConfig.smoothKeyboard) {
AndroidUtilities.removeAdjustResize(getParentActivity(), classGuid);
}
AndroidUtilities.updateViewVisibilityAnimated(avatarContainer, !expanded, 0.95f, true);
}
};
sharedMediaLayout.setPinnedToTop(true);
sharedMediaLayout.getSearchItem().setTranslationY(0);
sharedMediaLayout.photoVideoOptionsItem.setTranslationY(0);
fragmentView.addView(sharedMediaLayout);
fragmentView.addView(actionBar);
fragmentView.addView(avatarContainer);
TLObject avatarObject = null;
if (DialogObject.isEncryptedDialog(dialogId)) {
TLRPC.EncryptedChat encryptedChat = getMessagesController().getEncryptedChat(DialogObject.getEncryptedChatId(dialogId));
if (encryptedChat != null) {
TLRPC.User user = getMessagesController().getUser(encryptedChat.user_id);
if (user != null) {
nameTextView.setText(ContactsController.formatName(user.first_name, user.last_name));
avatarDrawable.setInfo(user);
avatarObject = user;
}
}
} else if (DialogObject.isUserDialog(dialogId)) {
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(dialogId);
if (user != null) {
if (user.self) {
nameTextView.setText(LocaleController.getString("SavedMessages", R.string.SavedMessages));
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_SAVED);
avatarDrawable.setSmallSize(true);
} else {
nameTextView.setText(ContactsController.formatName(user.first_name, user.last_name));
avatarDrawable.setInfo(user);
avatarObject = user;
}
}
} else {
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-dialogId);
if (chat != null) {
nameTextView.setText(chat.title);
avatarDrawable.setInfo(chat);
avatarObject = chat;
}
}
final ImageLocation thumbLocation = ImageLocation.getForUserOrChat(avatarObject, ImageLocation.TYPE_SMALL);
avatarImageView.setImage(thumbLocation, "50_50", avatarDrawable, avatarObject);
if (TextUtils.isEmpty(nameTextView.getText())) {
nameTextView.setText(LocaleController.getString("SharedContentTitle", R.string.SharedContentTitle));
}
if (sharedMediaLayout.isSearchItemVisible()) {
sharedMediaLayout.getSearchItem().setVisibility(View.VISIBLE);
}
if (sharedMediaLayout.isCalendarItemVisible()) {
sharedMediaLayout.photoVideoOptionsItem.setVisibility(View.VISIBLE);
} else {
sharedMediaLayout.photoVideoOptionsItem.setVisibility(View.INVISIBLE);
}
AndroidUtilities.updateViewVisibilityAnimated(avatarContainer, true, 1, false);
updateMediaCount();
updateColors();
return fragmentView;
}
Aggregations