use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ContextLinkCell method setAttachType.
private void setAttachType() {
currentMessageObject = null;
documentAttachType = DOCUMENT_ATTACH_TYPE_NONE;
if (documentAttach != null) {
if (MessageObject.isGifDocument(documentAttach)) {
documentAttachType = DOCUMENT_ATTACH_TYPE_GIF;
} else if (MessageObject.isStickerDocument(documentAttach) || MessageObject.isAnimatedStickerDocument(documentAttach, true)) {
documentAttachType = DOCUMENT_ATTACH_TYPE_STICKER;
} else if (MessageObject.isMusicDocument(documentAttach)) {
documentAttachType = DOCUMENT_ATTACH_TYPE_MUSIC;
} else if (MessageObject.isVoiceDocument(documentAttach)) {
documentAttachType = DOCUMENT_ATTACH_TYPE_AUDIO;
}
} else if (inlineResult != null) {
if (inlineResult.photo != null) {
documentAttachType = DOCUMENT_ATTACH_TYPE_PHOTO;
} else if (inlineResult.type.equals("audio")) {
documentAttachType = DOCUMENT_ATTACH_TYPE_MUSIC;
} else if (inlineResult.type.equals("voice")) {
documentAttachType = DOCUMENT_ATTACH_TYPE_AUDIO;
}
}
if (documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO || documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC) {
TLRPC.TL_message message = new TLRPC.TL_message();
message.out = true;
message.id = -Utilities.random.nextInt();
message.peer_id = new TLRPC.TL_peerUser();
message.from_id = new TLRPC.TL_peerUser();
message.peer_id.user_id = message.from_id.user_id = UserConfig.getInstance(currentAccount).getClientUserId();
message.date = (int) (System.currentTimeMillis() / 1000);
message.message = "";
message.media = new TLRPC.TL_messageMediaDocument();
message.media.flags |= 3;
message.media.document = new TLRPC.TL_document();
message.media.document.file_reference = new byte[0];
message.flags |= TLRPC.MESSAGE_FLAG_HAS_MEDIA | TLRPC.MESSAGE_FLAG_HAS_FROM_ID;
if (documentAttach != null) {
message.media.document = documentAttach;
message.attachPath = "";
} else {
String ext = ImageLoader.getHttpUrlExtension(inlineResult.content.url, documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC ? "mp3" : "ogg");
message.media.document.id = 0;
message.media.document.access_hash = 0;
message.media.document.date = message.date;
message.media.document.mime_type = "audio/" + ext;
message.media.document.size = 0;
message.media.document.dc_id = 0;
TLRPC.TL_documentAttributeAudio attributeAudio = new TLRPC.TL_documentAttributeAudio();
attributeAudio.duration = MessageObject.getInlineResultDuration(inlineResult);
attributeAudio.title = inlineResult.title != null ? inlineResult.title : "";
attributeAudio.performer = inlineResult.description != null ? inlineResult.description : "";
attributeAudio.flags |= 3;
if (documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO) {
attributeAudio.voice = true;
}
message.media.document.attributes.add(attributeAudio);
TLRPC.TL_documentAttributeFilename fileName = new TLRPC.TL_documentAttributeFilename();
fileName.file_name = Utilities.MD5(inlineResult.content.url) + "." + ImageLoader.getHttpUrlExtension(inlineResult.content.url, documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC ? "mp3" : "ogg");
message.media.document.attributes.add(fileName);
message.attachPath = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), Utilities.MD5(inlineResult.content.url) + "." + ImageLoader.getHttpUrlExtension(inlineResult.content.url, documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC ? "mp3" : "ogg")).getAbsolutePath();
}
currentMessageObject = new MessageObject(currentAccount, message, false, true);
}
}
use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class PipRoundVideoView method show.
public void show(Activity activity, Runnable closeRunnable) {
if (activity == null) {
return;
}
instance = this;
onCloseRunnable = closeRunnable;
windowView = new FrameLayout(activity) {
private float startX;
private float startY;
private boolean dragging;
private boolean startDragging;
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
startX = event.getRawX();
startY = event.getRawY();
startDragging = true;
}
return true;
}
@Override
public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
super.requestDisallowInterceptTouchEvent(disallowIntercept);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!startDragging && !dragging) {
return false;
}
float x = event.getRawX();
float y = event.getRawY();
if (event.getAction() == MotionEvent.ACTION_MOVE) {
float dx = (x - startX);
float dy = (y - startY);
if (startDragging) {
if (Math.abs(dx) >= AndroidUtilities.getPixelsInCM(0.3f, true) || Math.abs(dy) >= AndroidUtilities.getPixelsInCM(0.3f, false)) {
dragging = true;
startDragging = false;
}
} else if (dragging) {
windowLayoutParams.x += dx;
windowLayoutParams.y += dy;
int maxDiff = videoWidth / 2;
if (windowLayoutParams.x < -maxDiff) {
windowLayoutParams.x = -maxDiff;
} else if (windowLayoutParams.x > AndroidUtilities.displaySize.x - windowLayoutParams.width + maxDiff) {
windowLayoutParams.x = AndroidUtilities.displaySize.x - windowLayoutParams.width + maxDiff;
}
float alpha = 1.0f;
if (windowLayoutParams.x < 0) {
alpha = 1.0f + windowLayoutParams.x / (float) maxDiff * 0.5f;
} else if (windowLayoutParams.x > AndroidUtilities.displaySize.x - windowLayoutParams.width) {
alpha = 1.0f - (windowLayoutParams.x - AndroidUtilities.displaySize.x + windowLayoutParams.width) / (float) maxDiff * 0.5f;
}
if (windowView.getAlpha() != alpha) {
windowView.setAlpha(alpha);
}
maxDiff = 0;
if (windowLayoutParams.y < -maxDiff) {
windowLayoutParams.y = -maxDiff;
} else if (windowLayoutParams.y > AndroidUtilities.displaySize.y - windowLayoutParams.height + maxDiff) {
windowLayoutParams.y = AndroidUtilities.displaySize.y - windowLayoutParams.height + maxDiff;
}
windowManager.updateViewLayout(windowView, windowLayoutParams);
startX = x;
startY = y;
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
if (startDragging && !dragging) {
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if (messageObject != null) {
if (MediaController.getInstance().isMessagePaused()) {
MediaController.getInstance().playMessage(messageObject);
} else {
MediaController.getInstance().pauseMessage(messageObject);
}
}
}
dragging = false;
startDragging = false;
animateToBoundsMaybe();
}
return true;
}
@Override
protected void onDraw(Canvas canvas) {
if (Theme.chat_roundVideoShadow != null) /* && aspectRatioFrameLayout.isDrawingReady()*/
{
Theme.chat_roundVideoShadow.setAlpha((int) (getAlpha() * 255));
Theme.chat_roundVideoShadow.setBounds(AndroidUtilities.dp(1), AndroidUtilities.dp(2), AndroidUtilities.dp(125), AndroidUtilities.dp(125));
Theme.chat_roundVideoShadow.draw(canvas);
Theme.chat_docBackPaint.setColor(Theme.getColor(Theme.key_chat_inBubble));
Theme.chat_docBackPaint.setAlpha((int) (getAlpha() * 255));
canvas.drawCircle(AndroidUtilities.dp(3 + 60), AndroidUtilities.dp(3 + 60), AndroidUtilities.dp(59.5f), Theme.chat_docBackPaint);
}
}
};
windowView.setWillNotDraw(false);
videoWidth = AndroidUtilities.dp(120 + 6);
videoHeight = AndroidUtilities.dp(120 + 6);
if (Build.VERSION.SDK_INT >= 21) {
aspectRatioFrameLayout = new AspectRatioFrameLayout(activity) {
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
boolean result = super.drawChild(canvas, child, drawingTime);
if (child == textureView) {
MessageObject currentMessageObject = MediaController.getInstance().getPlayingMessageObject();
if (currentMessageObject != null) {
rect.set(AndroidUtilities.dpf2(1.5f), AndroidUtilities.dpf2(1.5f), getMeasuredWidth() - AndroidUtilities.dpf2(1.5f), getMeasuredHeight() - AndroidUtilities.dpf2(1.5f));
canvas.drawArc(rect, -90, 360 * currentMessageObject.audioProgress, false, Theme.chat_radialProgressPaint);
}
}
return result;
}
};
aspectRatioFrameLayout.setOutlineProvider(new ViewOutlineProvider() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void getOutline(View view, Outline outline) {
outline.setOval(0, 0, AndroidUtilities.dp(120), AndroidUtilities.dp(120));
}
});
aspectRatioFrameLayout.setClipToOutline(true);
} else {
final Paint aspectPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
aspectPaint.setColor(0xff000000);
aspectPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
aspectRatioFrameLayout = new AspectRatioFrameLayout(activity) {
private Path aspectPath = new Path();
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
aspectPath.reset();
aspectPath.addCircle(w / 2, h / 2, w / 2, Path.Direction.CW);
aspectPath.toggleInverseFillType();
}
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
canvas.drawPath(aspectPath, aspectPaint);
}
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
boolean result;
try {
result = super.drawChild(canvas, child, drawingTime);
} catch (Throwable ignore) {
result = false;
}
if (child == textureView) {
MessageObject currentMessageObject = MediaController.getInstance().getPlayingMessageObject();
if (currentMessageObject != null) {
rect.set(AndroidUtilities.dpf2(1.5f), AndroidUtilities.dpf2(1.5f), getMeasuredWidth() - AndroidUtilities.dpf2(1.5f), getMeasuredHeight() - AndroidUtilities.dpf2(1.5f));
canvas.drawArc(rect, -90, 360 * currentMessageObject.audioProgress, false, Theme.chat_radialProgressPaint);
}
}
return result;
}
};
aspectRatioFrameLayout.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
aspectRatioFrameLayout.setAspectRatio(1.0f, 0);
windowView.addView(aspectRatioFrameLayout, LayoutHelper.createFrame(120, 120, Gravity.LEFT | Gravity.TOP, 3, 3, 0, 0));
windowView.setAlpha(1.0f);
windowView.setScaleX(0.8f);
windowView.setScaleY(0.8f);
textureView = new TextureView(activity);
float scale = (AndroidUtilities.dpf2(120) + AndroidUtilities.dpf2(2)) / AndroidUtilities.dpf2(120);
textureView.setScaleX(scale);
textureView.setScaleY(scale);
aspectRatioFrameLayout.addView(textureView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
imageView = new ImageView(activity);
aspectRatioFrameLayout.addView(imageView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
imageView.setVisibility(View.INVISIBLE);
windowManager = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
preferences = ApplicationLoader.applicationContext.getSharedPreferences("pipconfig", Context.MODE_PRIVATE);
int sidex = preferences.getInt("sidex", 1);
int sidey = preferences.getInt("sidey", 0);
float px = preferences.getFloat("px", 0);
float py = preferences.getFloat("py", 0);
try {
windowLayoutParams = new WindowManager.LayoutParams();
windowLayoutParams.width = videoWidth;
windowLayoutParams.height = videoHeight;
windowLayoutParams.x = getSideCoord(true, sidex, px, videoWidth);
windowLayoutParams.y = getSideCoord(false, sidey, py, videoHeight);
windowLayoutParams.format = PixelFormat.TRANSLUCENT;
windowLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
windowManager.addView(windowView, windowLayoutParams);
} catch (Exception e) {
FileLog.e(e);
return;
}
parentActivity = activity;
currentAccount = UserConfig.selectedAccount;
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingProgressDidChanged);
runShowHideAnimation(true);
}
use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatListItemAnimator method groupWillChanged.
public void groupWillChanged(MessageObject.GroupedMessages groupedMessages) {
if (groupedMessages == null) {
return;
}
if (groupedMessages.messages.size() == 0) {
groupedMessages.transitionParams.drawBackgroundForDeletedItems = true;
} else {
if (groupedMessages.transitionParams.top == 0 && groupedMessages.transitionParams.bottom == 0 && groupedMessages.transitionParams.left == 0 && groupedMessages.transitionParams.right == 0) {
int n = recyclerListView.getChildCount();
for (int i = 0; i < n; i++) {
View child = recyclerListView.getChildAt(i);
if (child instanceof ChatMessageCell) {
ChatMessageCell cell = (ChatMessageCell) child;
MessageObject messageObject = cell.getMessageObject();
if (cell.getTransitionParams().wasDraw && groupedMessages.messages.contains(messageObject)) {
groupedMessages.transitionParams.top = cell.getTop() + cell.getBackgroundDrawableTop();
groupedMessages.transitionParams.bottom = cell.getTop() + cell.getBackgroundDrawableBottom();
groupedMessages.transitionParams.left = cell.getLeft() + cell.getBackgroundDrawableLeft();
groupedMessages.transitionParams.right = cell.getLeft() + cell.getBackgroundDrawableRight();
groupedMessages.transitionParams.drawCaptionLayout = cell.hasCaptionLayout();
groupedMessages.transitionParams.pinnedTop = cell.isPinnedTop();
groupedMessages.transitionParams.pinnedBotton = cell.isPinnedBottom();
groupedMessages.transitionParams.isNewGroup = true;
break;
}
}
}
}
willChangedGroups.add(groupedMessages);
}
}
use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ArticleViewer method setParentActivity.
public void setParentActivity(Activity activity, BaseFragment fragment) {
parentFragment = fragment;
currentAccount = UserConfig.selectedAccount;
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingProgressDidChanged);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidReset);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingPlayStateChanged);
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidStart);
if (parentActivity == activity) {
updatePaintColors();
refreshThemeColors();
return;
}
parentActivity = activity;
SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("articles", Activity.MODE_PRIVATE);
selectedFont = sharedPreferences.getInt("font_type", 0);
createPaint(false);
backgroundPaint = new Paint();
layerShadowDrawable = activity.getResources().getDrawable(R.drawable.layer_shadow);
slideDotDrawable = activity.getResources().getDrawable(R.drawable.slide_dot_small);
slideDotBigDrawable = activity.getResources().getDrawable(R.drawable.slide_dot_big);
scrimPaint = new Paint();
windowView = new WindowView(activity);
windowView.setWillNotDraw(false);
windowView.setClipChildren(true);
windowView.setFocusable(false);
containerView = new FrameLayout(activity) {
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
if (windowView.movingPage) {
int width = getMeasuredWidth();
int translationX = (int) listView[0].getTranslationX();
int clipLeft = 0;
int clipRight = width;
if (child == listView[1]) {
clipRight = translationX;
} else if (child == listView[0]) {
clipLeft = translationX;
}
final int restoreCount = canvas.save();
canvas.clipRect(clipLeft, 0, clipRight, getHeight());
final boolean result = super.drawChild(canvas, child, drawingTime);
canvas.restoreToCount(restoreCount);
if (translationX != 0) {
if (child == listView[0]) {
final float alpha = Math.max(0, Math.min((width - translationX) / (float) AndroidUtilities.dp(20), 1.0f));
layerShadowDrawable.setBounds(translationX - layerShadowDrawable.getIntrinsicWidth(), child.getTop(), translationX, child.getBottom());
layerShadowDrawable.setAlpha((int) (0xff * alpha));
layerShadowDrawable.draw(canvas);
} else if (child == listView[1]) {
float opacity = Math.min(0.8f, (width - translationX) / (float) width);
if (opacity < 0) {
opacity = 0;
}
scrimPaint.setColor((int) (((0x99000000 & 0xff000000) >>> 24) * opacity) << 24);
canvas.drawRect(clipLeft, 0, clipRight, getHeight(), scrimPaint);
}
}
return result;
} else {
return super.drawChild(canvas, child, drawingTime);
}
}
};
windowView.addView(containerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
// containerView.setFitsSystemWindows(true);
if (Build.VERSION.SDK_INT >= 21) {
windowView.setFitsSystemWindows(true);
containerView.setOnApplyWindowInsetsListener((v, insets) -> {
if (Build.VERSION.SDK_INT >= 30) {
return WindowInsets.CONSUMED;
} else {
return insets.consumeSystemWindowInsets();
}
});
}
fullscreenVideoContainer = new FrameLayout(activity);
fullscreenVideoContainer.setBackgroundColor(0xff000000);
fullscreenVideoContainer.setVisibility(View.INVISIBLE);
windowView.addView(fullscreenVideoContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
fullscreenAspectRatioView = new AspectRatioFrameLayout(activity);
fullscreenAspectRatioView.setVisibility(View.GONE);
fullscreenVideoContainer.addView(fullscreenAspectRatioView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER));
fullscreenTextureView = new TextureView(activity);
listView = new RecyclerListView[2];
adapter = new WebpageAdapter[2];
layoutManager = new LinearLayoutManager[2];
for (int i = 0; i < listView.length; i++) {
WebpageAdapter webpageAdapter = adapter[i] = new WebpageAdapter(parentActivity);
listView[i] = new RecyclerListView(activity) {
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
int count = getChildCount();
for (int a = 0; a < count; a++) {
View child = getChildAt(a);
if (child.getTag() instanceof Integer) {
Integer tag = (Integer) child.getTag();
if (tag == 90) {
int bottom = child.getBottom();
if (bottom < getMeasuredHeight()) {
int height = getMeasuredHeight();
child.layout(0, height - child.getMeasuredHeight(), child.getMeasuredWidth(), height);
break;
}
}
}
}
}
@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
if (pressedLinkOwnerLayout != null && pressedLink == null && (popupWindow == null || !popupWindow.isShowing()) && (e.getAction() == MotionEvent.ACTION_UP || e.getAction() == MotionEvent.ACTION_CANCEL)) {
pressedLink = null;
pressedLinkOwnerLayout = null;
pressedLinkOwnerView = null;
} else if (pressedLinkOwnerLayout != null && pressedLink != null && e.getAction() == MotionEvent.ACTION_UP) {
checkLayoutForLinks(webpageAdapter, e, pressedLinkOwnerView, pressedLinkOwnerLayout, 0, 0);
}
return super.onInterceptTouchEvent(e);
}
@Override
public boolean onTouchEvent(MotionEvent e) {
if (pressedLinkOwnerLayout != null && pressedLink == null && (popupWindow == null || !popupWindow.isShowing()) && (e.getAction() == MotionEvent.ACTION_UP || e.getAction() == MotionEvent.ACTION_CANCEL)) {
pressedLink = null;
pressedLinkOwnerLayout = null;
pressedLinkOwnerView = null;
}
return super.onTouchEvent(e);
}
@Override
public void setTranslationX(float translationX) {
super.setTranslationX(translationX);
if (windowView.movingPage) {
containerView.invalidate();
float progress = translationX / getMeasuredWidth();
setCurrentHeaderHeight((int) (windowView.startMovingHeaderHeight + (AndroidUtilities.dp(56) - windowView.startMovingHeaderHeight) * progress));
}
}
};
((DefaultItemAnimator) listView[i].getItemAnimator()).setDelayAnimations(false);
listView[i].setLayoutManager(layoutManager[i] = new LinearLayoutManager(parentActivity, LinearLayoutManager.VERTICAL, false));
listView[i].setAdapter(webpageAdapter);
listView[i].setClipToPadding(false);
listView[i].setVisibility(i == 0 ? View.VISIBLE : View.GONE);
listView[i].setPadding(0, AndroidUtilities.dp(56), 0, 0);
listView[i].setTopGlowOffset(AndroidUtilities.dp(56));
containerView.addView(listView[i], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView[i].setOnItemLongClickListener((view, position) -> {
if (view instanceof BlockRelatedArticlesCell) {
BlockRelatedArticlesCell cell = (BlockRelatedArticlesCell) view;
showCopyPopup(cell.currentBlock.parent.articles.get(cell.currentBlock.num).url);
return true;
}
return false;
});
listView[i].setOnItemClickListener((view, position, x, y) -> {
if (textSelectionHelper != null) {
if (textSelectionHelper.isSelectionMode()) {
textSelectionHelper.clear();
return;
}
textSelectionHelper.clear();
}
if (view instanceof ReportCell && webpageAdapter.currentPage != null) {
ReportCell cell = (ReportCell) view;
if (previewsReqId != 0 || cell.hasViews && x < view.getMeasuredWidth() / 2) {
return;
}
TLObject object = MessagesController.getInstance(currentAccount).getUserOrChat("previews");
if (object instanceof TLRPC.TL_user) {
openPreviewsChat((TLRPC.User) object, webpageAdapter.currentPage.id);
} else {
final int currentAccount = UserConfig.selectedAccount;
final long pageId = webpageAdapter.currentPage.id;
showProgressView(true, true);
TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
req.username = "previews";
previewsReqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
if (previewsReqId == 0) {
return;
}
previewsReqId = 0;
showProgressView(true, false);
if (response != null) {
TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
MessagesController.getInstance(currentAccount).putUsers(res.users, false);
MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, false, true);
if (!res.users.isEmpty()) {
openPreviewsChat(res.users.get(0), pageId);
}
}
}));
}
} else if (position >= 0 && position < webpageAdapter.localBlocks.size()) {
TLRPC.PageBlock pageBlock = webpageAdapter.localBlocks.get(position);
TLRPC.PageBlock originalBlock = pageBlock;
pageBlock = getLastNonListPageBlock(pageBlock);
if (pageBlock instanceof TL_pageBlockDetailsChild) {
TL_pageBlockDetailsChild detailsChild = (TL_pageBlockDetailsChild) pageBlock;
pageBlock = detailsChild.block;
}
if (pageBlock instanceof TLRPC.TL_pageBlockChannel) {
TLRPC.TL_pageBlockChannel pageBlockChannel = (TLRPC.TL_pageBlockChannel) pageBlock;
MessagesController.getInstance(currentAccount).openByUserName(pageBlockChannel.channel.username, parentFragment, 2);
close(false, true);
} else if (pageBlock instanceof TL_pageBlockRelatedArticlesChild) {
TL_pageBlockRelatedArticlesChild pageBlockRelatedArticlesChild = (TL_pageBlockRelatedArticlesChild) pageBlock;
openWebpageUrl(pageBlockRelatedArticlesChild.parent.articles.get(pageBlockRelatedArticlesChild.num).url, null);
} else if (pageBlock instanceof TLRPC.TL_pageBlockDetails) {
view = getLastNonListCell(view);
if (!(view instanceof BlockDetailsCell)) {
return;
}
pressedLinkOwnerLayout = null;
pressedLinkOwnerView = null;
int index = webpageAdapter.blocks.indexOf(originalBlock);
if (index < 0) {
return;
}
TLRPC.TL_pageBlockDetails pageBlockDetails = (TLRPC.TL_pageBlockDetails) pageBlock;
pageBlockDetails.open = !pageBlockDetails.open;
int oldCount = webpageAdapter.getItemCount();
webpageAdapter.updateRows();
int newCount = webpageAdapter.getItemCount();
int changeCount = Math.abs(newCount - oldCount);
BlockDetailsCell cell = (BlockDetailsCell) view;
cell.arrow.setAnimationProgressAnimated(pageBlockDetails.open ? 0.0f : 1.0f);
cell.invalidate();
if (changeCount != 0) {
if (pageBlockDetails.open) {
webpageAdapter.notifyItemRangeInserted(position + 1, changeCount);
} else {
webpageAdapter.notifyItemRangeRemoved(position + 1, changeCount);
}
}
}
}
});
listView[i].setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
textSelectionHelper.stopScrolling();
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (recyclerView.getChildCount() == 0) {
return;
}
textSelectionHelper.onParentScrolled();
headerView.invalidate();
checkScroll(dy);
}
});
}
headerPaint.setColor(0xff000000);
statusBarPaint.setColor(0xff000000);
headerProgressPaint.setColor(0xff242426);
headerView = new FrameLayout(activity) {
@Override
protected void onDraw(Canvas canvas) {
int width = getMeasuredWidth();
int height = getMeasuredHeight();
canvas.drawRect(0, 0, width, height, headerPaint);
if (layoutManager == null) {
return;
}
int first = layoutManager[0].findFirstVisibleItemPosition();
int last = layoutManager[0].findLastVisibleItemPosition();
int count = layoutManager[0].getItemCount();
View view;
if (last >= count - 2) {
view = layoutManager[0].findViewByPosition(count - 2);
} else {
view = layoutManager[0].findViewByPosition(first);
}
if (view == null) {
return;
}
float itemProgress = width / (float) (count - 1);
int childCount = layoutManager[0].getChildCount();
float viewHeight = view.getMeasuredHeight();
float viewProgress;
if (last >= count - 2) {
viewProgress = (count - 2 - first) * itemProgress * (listView[0].getMeasuredHeight() - view.getTop()) / viewHeight;
} else {
viewProgress = itemProgress * (1.0f - (Math.min(0, view.getTop() - listView[0].getPaddingTop()) + viewHeight) / viewHeight);
}
float progress = first * itemProgress + viewProgress;
canvas.drawRect(0, 0, progress, height, headerProgressPaint);
}
};
headerView.setWillNotDraw(false);
containerView.addView(headerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 56));
headerView.setOnClickListener(v -> listView[0].smoothScrollToPosition(0));
titleTextView = new SimpleTextView(activity);
titleTextView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
titleTextView.setTextSize(20);
titleTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
titleTextView.setTextColor(0xffb3b3b3);
titleTextView.setPivotX(0.0f);
titleTextView.setPivotY(AndroidUtilities.dp(28));
headerView.addView(titleTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 56, Gravity.LEFT | Gravity.TOP, 72, 0, 48 * 2, 0));
lineProgressView = new LineProgressView(activity);
lineProgressView.setProgressColor(0xffffffff);
lineProgressView.setPivotX(0.0f);
lineProgressView.setPivotY(AndroidUtilities.dp(2));
headerView.addView(lineProgressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 2, Gravity.LEFT | Gravity.BOTTOM, 0, 0, 0, 1));
lineProgressTickRunnable = () -> {
float progressLeft = 0.7f - lineProgressView.getCurrentProgress();
if (progressLeft > 0.0f) {
float tick;
if (progressLeft < 0.25f) {
tick = 0.01f;
} else {
tick = 0.02f;
}
lineProgressView.setProgress(lineProgressView.getCurrentProgress() + tick, true);
AndroidUtilities.runOnUIThread(lineProgressTickRunnable, 100);
}
};
menuContainer = new FrameLayout(activity);
headerView.addView(menuContainer, LayoutHelper.createFrame(48, 56, Gravity.TOP | Gravity.RIGHT));
searchShadow = new View(activity);
searchShadow.setBackgroundResource(R.drawable.header_shadow);
searchShadow.setAlpha(0.0f);
containerView.addView(searchShadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.LEFT | Gravity.TOP, 0, 56, 0, 0));
searchContainer = new FrameLayout(parentActivity);
searchContainer.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
searchContainer.setVisibility(View.INVISIBLE);
if (Build.VERSION.SDK_INT < 21) {
searchContainer.setAlpha(0.0f);
}
headerView.addView(searchContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 56));
searchField = new EditTextBoldCursor(parentActivity) {
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (!AndroidUtilities.showKeyboard(this)) {
clearFocus();
requestFocus();
}
}
return super.onTouchEvent(event);
}
};
searchField.setCursorWidth(1.5f);
searchField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
searchField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
searchField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
searchField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
searchField.setSingleLine(true);
searchField.setHint(LocaleController.getString("Search", R.string.Search));
searchField.setBackgroundResource(0);
searchField.setPadding(0, 0, 0, 0);
int inputType = searchField.getInputType() | EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
searchField.setInputType(inputType);
if (Build.VERSION.SDK_INT < 23) {
searchField.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
public void onDestroyActionMode(ActionMode mode) {
}
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
return false;
}
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
return false;
}
});
}
searchField.setOnEditorActionListener((v, actionId, event) -> {
if (event != null && (event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_SEARCH || event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
AndroidUtilities.hideKeyboard(searchField);
}
return false;
});
searchField.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (ignoreOnTextChange) {
ignoreOnTextChange = false;
return;
}
processSearch(s.toString().toLowerCase());
if (clearButton != null) {
if (TextUtils.isEmpty(s)) {
if (clearButton.getTag() != null) {
clearButton.setTag(null);
clearButton.clearAnimation();
if (animateClear) {
clearButton.animate().setInterpolator(new DecelerateInterpolator()).alpha(0.0f).setDuration(180).scaleY(0.0f).scaleX(0.0f).rotation(45).withEndAction(() -> clearButton.setVisibility(View.INVISIBLE)).start();
} else {
clearButton.setAlpha(0.0f);
clearButton.setRotation(45);
clearButton.setScaleX(0.0f);
clearButton.setScaleY(0.0f);
clearButton.setVisibility(View.INVISIBLE);
animateClear = true;
}
}
} else {
if (clearButton.getTag() == null) {
clearButton.setTag(1);
clearButton.clearAnimation();
clearButton.setVisibility(View.VISIBLE);
if (animateClear) {
clearButton.animate().setInterpolator(new DecelerateInterpolator()).alpha(1.0f).setDuration(180).scaleY(1.0f).scaleX(1.0f).rotation(0).start();
} else {
clearButton.setAlpha(1.0f);
clearButton.setRotation(0);
clearButton.setScaleX(1.0f);
clearButton.setScaleY(1.0f);
animateClear = true;
}
}
}
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
searchField.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME_ACTION_SEARCH);
searchField.setTextIsSelectable(false);
searchContainer.addView(searchField, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 36, Gravity.CENTER_VERTICAL, 72, 0, 48, 0));
clearButton = new ImageView(parentActivity) {
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
clearAnimation();
if (getTag() == null) {
clearButton.setVisibility(INVISIBLE);
clearButton.setAlpha(0.0f);
clearButton.setRotation(45);
clearButton.setScaleX(0.0f);
clearButton.setScaleY(0.0f);
} else {
clearButton.setAlpha(1.0f);
clearButton.setRotation(0);
clearButton.setScaleX(1.0f);
clearButton.setScaleY(1.0f);
}
}
};
clearButton.setImageDrawable(new CloseProgressDrawable2());
clearButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText), PorterDuff.Mode.MULTIPLY));
clearButton.setScaleType(ImageView.ScaleType.CENTER);
clearButton.setAlpha(0.0f);
clearButton.setRotation(45);
clearButton.setScaleX(0.0f);
clearButton.setScaleY(0.0f);
clearButton.setOnClickListener(v -> {
if (searchField.length() != 0) {
searchField.setText("");
}
searchField.requestFocus();
AndroidUtilities.showKeyboard(searchField);
});
clearButton.setContentDescription(LocaleController.getString("ClearButton", R.string.ClearButton));
searchContainer.addView(clearButton, LayoutHelper.createFrame(48, LayoutHelper.MATCH_PARENT, Gravity.CENTER_VERTICAL | Gravity.RIGHT));
backButton = new ImageView(activity);
backButton.setScaleType(ImageView.ScaleType.CENTER);
backDrawable = new BackDrawable(false);
backDrawable.setAnimationTime(200.0f);
backDrawable.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
backDrawable.setRotatedColor(0xffb3b3b3);
backDrawable.setRotation(1.0f, false);
backButton.setImageDrawable(backDrawable);
backButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
headerView.addView(backButton, LayoutHelper.createFrame(54, 56));
backButton.setOnClickListener(v -> {
/*if (collapsed) {
uncollapse();
} else {
collapse();
}*/
if (searchContainer.getTag() != null) {
showSearch(false);
} else {
close(true, true);
}
});
backButton.setContentDescription(LocaleController.getString("AccDescrGoBack", R.string.AccDescrGoBack));
menuButton = new ActionBarMenuItem(parentActivity, null, Theme.ACTION_BAR_WHITE_SELECTOR_COLOR, 0xffb3b3b3) {
@Override
public void toggleSubMenu() {
super.toggleSubMenu();
listView[0].stopScroll();
checkScrollAnimated();
}
};
menuButton.setLayoutInScreen(true);
menuButton.setDuplicateParentStateEnabled(false);
menuButton.setClickable(true);
menuButton.setIcon(R.drawable.ic_ab_other);
menuButton.addSubItem(search_item, R.drawable.msg_search, LocaleController.getString("Search", R.string.Search));
menuButton.addSubItem(share_item, R.drawable.msg_share, LocaleController.getString("ShareFile", R.string.ShareFile));
menuButton.addSubItem(open_item, R.drawable.msg_openin, LocaleController.getString("OpenInExternalApp", R.string.OpenInExternalApp));
menuButton.addSubItem(settings_item, R.drawable.menu_settings, LocaleController.getString("Settings", R.string.Settings));
menuButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
menuButton.setContentDescription(LocaleController.getString("AccDescrMoreOptions", R.string.AccDescrMoreOptions));
menuContainer.addView(menuButton, LayoutHelper.createFrame(48, 56));
progressView = new ContextProgressView(activity, 2);
progressView.setVisibility(View.GONE);
menuContainer.addView(progressView, LayoutHelper.createFrame(48, 56));
menuButton.setOnClickListener(v -> menuButton.toggleSubMenu());
menuButton.setDelegate(id -> {
if (adapter[0].currentPage == null || parentActivity == null) {
return;
}
if (id == search_item) {
showSearch(true);
} else if (id == share_item) {
showDialog(new ShareAlert(parentActivity, null, adapter[0].currentPage.url, false, adapter[0].currentPage.url, false));
} else if (id == open_item) {
String webPageUrl;
if (!TextUtils.isEmpty(adapter[0].currentPage.cached_page.url)) {
webPageUrl = adapter[0].currentPage.cached_page.url;
} else {
webPageUrl = adapter[0].currentPage.url;
}
Browser.openUrl(parentActivity, webPageUrl, true, false);
} else if (id == settings_item) {
BottomSheet.Builder builder = new BottomSheet.Builder(parentActivity);
builder.setApplyTopPadding(false);
LinearLayout settingsContainer = new LinearLayout(parentActivity);
settingsContainer.setPadding(0, 0, 0, AndroidUtilities.dp(4));
settingsContainer.setOrientation(LinearLayout.VERTICAL);
HeaderCell headerCell = new HeaderCell(parentActivity);
headerCell.setText(LocaleController.getString("FontSize", R.string.FontSize));
settingsContainer.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 3, 1, 3, 0));
TextSizeCell sizeCell = new TextSizeCell(parentActivity);
settingsContainer.addView(sizeCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 3, 0, 3, 0));
headerCell = new HeaderCell(parentActivity);
headerCell.setText(LocaleController.getString("FontType", R.string.FontType));
settingsContainer.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 3, 4, 3, 2));
for (int a = 0; a < 2; a++) {
fontCells[a] = new FontCell(parentActivity);
switch(a) {
case 0:
fontCells[a].setTextAndTypeface(LocaleController.getString("Default", R.string.Default), Typeface.DEFAULT);
break;
case 1:
fontCells[a].setTextAndTypeface("Serif", Typeface.SERIF);
break;
}
fontCells[a].select(a == selectedFont, false);
fontCells[a].setTag(a);
fontCells[a].setOnClickListener(v -> {
int num = (Integer) v.getTag();
selectedFont = num;
for (int a1 = 0; a1 < 2; a1++) {
fontCells[a1].select(a1 == num, true);
}
updatePaintFonts();
for (int i = 0; i < listView.length; i++) {
adapter[i].notifyDataSetChanged();
}
});
settingsContainer.addView(fontCells[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
}
builder.setCustomView(settingsContainer);
showDialog(linkSheet = builder.create());
}
});
searchPanel = new FrameLayout(parentActivity) {
@Override
public void onDraw(Canvas canvas) {
int bottom = Theme.chat_composeShadowDrawable.getIntrinsicHeight();
Theme.chat_composeShadowDrawable.setBounds(0, 0, getMeasuredWidth(), bottom);
Theme.chat_composeShadowDrawable.draw(canvas);
canvas.drawRect(0, bottom, getMeasuredWidth(), getMeasuredHeight(), Theme.chat_composeBackgroundPaint);
}
};
searchPanel.setOnTouchListener((v, event) -> true);
searchPanel.setWillNotDraw(false);
searchPanel.setVisibility(View.INVISIBLE);
searchPanel.setFocusable(true);
searchPanel.setFocusableInTouchMode(true);
searchPanel.setClickable(true);
searchPanel.setPadding(0, AndroidUtilities.dp(3), 0, 0);
containerView.addView(searchPanel, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM));
searchUpButton = new ImageView(parentActivity);
searchUpButton.setScaleType(ImageView.ScaleType.CENTER);
searchUpButton.setImageResource(R.drawable.msg_go_up);
searchUpButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText), PorterDuff.Mode.MULTIPLY));
searchUpButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.getColor(Theme.key_actionBarActionModeDefaultSelector), 1));
searchPanel.addView(searchUpButton, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP, 0, 0, 48, 0));
searchUpButton.setOnClickListener(view -> scrollToSearchIndex(currentSearchIndex - 1));
searchUpButton.setContentDescription(LocaleController.getString("AccDescrSearchNext", R.string.AccDescrSearchNext));
searchDownButton = new ImageView(parentActivity);
searchDownButton.setScaleType(ImageView.ScaleType.CENTER);
searchDownButton.setImageResource(R.drawable.msg_go_down);
searchDownButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText), PorterDuff.Mode.MULTIPLY));
searchDownButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.getColor(Theme.key_actionBarActionModeDefaultSelector), 1));
searchPanel.addView(searchDownButton, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP, 0, 0, 0, 0));
searchDownButton.setOnClickListener(view -> scrollToSearchIndex(currentSearchIndex + 1));
searchDownButton.setContentDescription(LocaleController.getString("AccDescrSearchPrev", R.string.AccDescrSearchPrev));
searchCountText = new SimpleTextView(parentActivity);
searchCountText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
searchCountText.setTextSize(15);
searchCountText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
searchCountText.setGravity(Gravity.LEFT);
searchPanel.addView(searchCountText, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.CENTER_VERTICAL, 18, 0, 108, 0));
windowLayoutParams = new WindowManager.LayoutParams();
windowLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
windowLayoutParams.format = PixelFormat.TRANSLUCENT;
windowLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
windowLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW - 1;
windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
if (Build.VERSION.SDK_INT >= 21) {
windowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
if (Build.VERSION.SDK_INT >= 28) {
windowLayoutParams.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
}
}
textSelectionHelper = new TextSelectionHelper.ArticleTextSelectionHelper();
textSelectionHelper.setParentView(listView[0]);
if (MessagesController.getGlobalMainSettings().getBoolean("translate_button", false)) {
textSelectionHelper.setOnTranslate((text, fromLang, toLang, onAlertDismiss) -> {
TranslateAlert.showAlert(parentActivity, parentFragment, fromLang, toLang, text, false, null, onAlertDismiss);
});
}
textSelectionHelper.layoutManager = layoutManager[0];
textSelectionHelper.setCallback(new TextSelectionHelper.Callback() {
@Override
public void onStateChanged(boolean isSelected) {
if (isSelected) {
showSearch(false);
}
}
@Override
public void onTextCopied() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
BulletinFactory.of(containerView, null).createCopyBulletin(LocaleController.getString("TextCopied", R.string.TextCopied)).show();
}
}
});
containerView.addView(textSelectionHelper.getOverlayView(activity));
pinchToZoomHelper = new PinchToZoomHelper(containerView, windowView);
pinchToZoomHelper.setClipBoundsListener(new PinchToZoomHelper.ClipBoundsListener() {
@Override
public void getClipTopBottom(float[] topBottom) {
topBottom[0] = currentHeaderHeight;
topBottom[1] = listView[0].getMeasuredHeight();
}
});
pinchToZoomHelper.setCallback(new PinchToZoomHelper.Callback() {
@Override
public void onZoomStarted(MessageObject messageObject) {
if (listView[0] != null) {
listView[0].cancelClickRunnables(true);
}
}
});
updatePaintColors();
}
use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatMessageCell method drawCaptionLayout.
private void drawCaptionLayout(Canvas canvas, StaticLayout captionLayout, boolean selectionOnly, float alpha) {
if (currentBackgroundDrawable != null && drawCommentButton && timeLayout != null) {
int x;
float y = layoutHeight + transitionParams.deltaBottom - AndroidUtilities.dp(18) - timeLayout.getHeight();
if (currentMessagesGroup != null) {
y += currentMessagesGroup.transitionParams.offsetBottom;
if (currentMessagesGroup.transitionParams.backgroundChangeBounds) {
y -= getTranslationY();
}
}
if (mediaBackground) {
x = backgroundDrawableLeft + AndroidUtilities.dp(12) + getExtraTextX();
} else {
x = backgroundDrawableLeft + AndroidUtilities.dp(drawPinnedBottom ? 12 : 18) + getExtraTextX();
}
int endX = x - getExtraTextX();
if (currentMessagesGroup != null && !currentMessageObject.isMusic() && !currentMessageObject.isDocument()) {
int dWidth = getGroupPhotosWidth();
if ((currentPosition.flags & MessageObject.POSITION_FLAG_LEFT) == 0) {
endX += Math.ceil(currentPosition.pw / 1000.0f * dWidth);
} else {
int firstLineWidth = 0;
for (int a = 0; a < currentMessagesGroup.posArray.size(); a++) {
MessageObject.GroupedMessagePosition position = currentMessagesGroup.posArray.get(a);
if (position.minY == 0) {
firstLineWidth += Math.ceil((position.pw + position.leftSpanOffset) / 1000.0f * dWidth);
} else {
break;
}
}
endX += firstLineWidth - AndroidUtilities.dp(9);
}
} else {
endX += backgroundWidth - (mediaBackground ? 0 : AndroidUtilities.dp(9));
}
int h;
int h2;
if (pinnedBottom) {
h = 2;
h2 = 3;
} else if (pinnedTop) {
h = 4;
h2 = 1;
} else {
h = 3;
h2 = 0;
}
int buttonX = getCurrentBackgroundLeft() + AndroidUtilities.dp(currentMessageObject.isOutOwner() || mediaBackground || drawPinnedBottom ? 2 : 8);
float buttonY = layoutHeight - AndroidUtilities.dp(45.1f - h2);
if (currentPosition != null && (currentPosition.flags & MessageObject.POSITION_FLAG_LEFT) == 0 && !currentMessagesGroup.hasSibling) {
endX += AndroidUtilities.dp(14);
buttonX -= AndroidUtilities.dp(10);
}
commentButtonRect.set(buttonX, (int) buttonY, endX - AndroidUtilities.dp(14), layoutHeight - AndroidUtilities.dp(h));
if (selectorDrawable[1] != null && selectorDrawableMaskType[1] == 2) {
selectorDrawable[1].setBounds(commentButtonRect);
selectorDrawable[1].draw(canvas);
}
if (currentPosition == null || (currentPosition.flags & MessageObject.POSITION_FLAG_LEFT) != 0 && currentPosition.minX == 0 && currentPosition.maxX == 0) {
Theme.chat_instantViewPaint.setColor(getThemedColor(Theme.key_chat_inPreviewInstantText));
boolean drawnAvatars = false;
int avatarsOffset = 2;
if (commentAvatarImages != null) {
int toAdd = AndroidUtilities.dp(17);
int ax = x + getExtraTextX();
for (int a = commentAvatarImages.length - 1; a >= 0; a--) {
if (!commentAvatarImagesVisible[a] || !commentAvatarImages[a].hasImageSet()) {
continue;
}
commentAvatarImages[a].setImageX(ax + toAdd * a);
commentAvatarImages[a].setImageY(y - AndroidUtilities.dp(4) + (pinnedBottom ? AndroidUtilities.dp(2) : 0));
if (a != commentAvatarImages.length - 1) {
canvas.drawCircle(commentAvatarImages[a].getCenterX(), commentAvatarImages[a].getCenterY(), AndroidUtilities.dp(13), currentBackgroundDrawable.getPaint());
}
commentAvatarImages[a].draw(canvas);
drawnAvatars = true;
if (a != 0) {
avatarsOffset += 17;
}
}
}
if (!mediaBackground || captionLayout != null || (!reactionsLayoutInBubble.isEmpty && !reactionsLayoutInBubble.isSmall)) {
if (isDrawSelectionBackground()) {
Theme.chat_replyLinePaint.setColor(getThemedColor(currentMessageObject.isOutOwner() ? Theme.key_chat_outVoiceSeekbarSelected : Theme.key_chat_inVoiceSeekbarSelected));
} else {
Theme.chat_replyLinePaint.setColor(getThemedColor(currentMessageObject.isOutOwner() ? Theme.key_chat_outVoiceSeekbar : Theme.key_chat_inVoiceSeekbar));
}
float ly = layoutHeight - AndroidUtilities.dp(45.1f - h2);
ly += transitionParams.deltaBottom;
if (currentMessagesGroup != null) {
ly += currentMessagesGroup.transitionParams.offsetBottom;
if (currentMessagesGroup.transitionParams.backgroundChangeBounds) {
ly -= getTranslationY();
}
}
canvas.drawLine(x, ly, endX - AndroidUtilities.dp(14), ly, Theme.chat_replyLinePaint);
}
if (commentLayout != null && drawSideButton != 3) {
Theme.chat_replyNamePaint.setColor(getThemedColor(currentMessageObject.isOutOwner() ? Theme.key_chat_outPreviewInstantText : Theme.key_chat_inPreviewInstantText));
commentX = x + AndroidUtilities.dp(33 + avatarsOffset);
if (drawCommentNumber) {
commentX += commentNumberWidth + AndroidUtilities.dp(4);
}
int prevAlpha = Theme.chat_replyNamePaint.getAlpha();
if (transitionParams.animateComments) {
if (transitionParams.animateCommentsLayout != null) {
canvas.save();
Theme.chat_replyNamePaint.setAlpha((int) (prevAlpha * (1.0 - transitionParams.animateChangeProgress)));
float cx = transitionParams.animateCommentX + (commentX - transitionParams.animateCommentX) * transitionParams.animateChangeProgress;
canvas.translate(cx, y - AndroidUtilities.dp(0.1f) + (pinnedBottom ? AndroidUtilities.dp(2) : 0));
transitionParams.animateCommentsLayout.draw(canvas);
canvas.restore();
}
}
canvas.save();
canvas.translate(x + AndroidUtilities.dp(33 + avatarsOffset), y - AndroidUtilities.dp(0.1f) + (pinnedBottom ? AndroidUtilities.dp(2) : 0));
if (!currentMessageObject.isSent()) {
Theme.chat_replyNamePaint.setAlpha(127);
Theme.chat_commentArrowDrawable.setAlpha(127);
Theme.chat_commentDrawable.setAlpha(127);
} else {
Theme.chat_commentArrowDrawable.setAlpha(255);
Theme.chat_commentDrawable.setAlpha(255);
}
if (drawCommentNumber || transitionParams.animateComments && transitionParams.animateDrawCommentNumber) {
if (drawCommentNumber && transitionParams.animateComments) {
if (transitionParams.animateDrawCommentNumber) {
Theme.chat_replyNamePaint.setAlpha(prevAlpha);
} else {
Theme.chat_replyNamePaint.setAlpha((int) (prevAlpha * transitionParams.animateChangeProgress));
}
}
commentNumberLayout.draw(canvas);
if (drawCommentNumber) {
canvas.translate(commentNumberWidth + AndroidUtilities.dp(4), 0);
}
}
if (transitionParams.animateComments && transitionParams.animateCommentsLayout != null) {
Theme.chat_replyNamePaint.setAlpha((int) (prevAlpha * transitionParams.animateChangeProgress));
} else {
Theme.chat_replyNamePaint.setAlpha((int) (prevAlpha * alpha));
}
commentLayout.draw(canvas);
canvas.restore();
commentUnreadX = x + commentWidth + AndroidUtilities.dp(33 + avatarsOffset) + AndroidUtilities.dp(9);
if (drawCommentNumber) {
commentUnreadX += commentNumberWidth + AndroidUtilities.dp(4);
}
TLRPC.MessageReplies replies = null;
if (currentMessagesGroup != null && !currentMessagesGroup.messages.isEmpty()) {
MessageObject messageObject = currentMessagesGroup.messages.get(0);
if (messageObject.hasReplies()) {
replies = messageObject.messageOwner.replies;
}
} else {
if (currentMessageObject.hasReplies()) {
replies = currentMessageObject.messageOwner.replies;
}
}
if (commentDrawUnread = (replies != null && replies.read_max_id != 0 && replies.read_max_id < replies.max_id)) {
int color = getThemedColor(Theme.key_chat_inInstant);
Theme.chat_docBackPaint.setColor(color);
int unreadX;
if (transitionParams.animateComments) {
if (!transitionParams.animateCommentDrawUnread) {
Theme.chat_docBackPaint.setAlpha((int) (Color.alpha(color) * transitionParams.animateChangeProgress));
}
unreadX = (int) (transitionParams.animateCommentUnreadX + (commentUnreadX - transitionParams.animateCommentUnreadX) * transitionParams.animateChangeProgress);
} else {
unreadX = commentUnreadX;
}
canvas.drawCircle(unreadX, y + AndroidUtilities.dp(8) + (pinnedBottom ? AndroidUtilities.dp(2) : 0), AndroidUtilities.dp(2.5f), Theme.chat_docBackPaint);
}
}
if (!drawnAvatars) {
setDrawableBounds(Theme.chat_commentDrawable, x, y - AndroidUtilities.dp(4) + (pinnedBottom ? AndroidUtilities.dp(2) : 0));
if (alpha != 1f) {
Theme.chat_commentDrawable.setAlpha((int) (255 * alpha));
Theme.chat_commentDrawable.draw(canvas);
Theme.chat_commentDrawable.setAlpha(255);
} else {
Theme.chat_commentDrawable.draw(canvas);
}
}
commentArrowX = endX - AndroidUtilities.dp(44);
int commentX;
if (transitionParams.animateComments) {
commentX = (int) (transitionParams.animateCommentArrowX + (commentArrowX - transitionParams.animateCommentArrowX) * transitionParams.animateChangeProgress);
} else {
commentX = commentArrowX;
}
float commentY = y - AndroidUtilities.dp(4) + (pinnedBottom ? AndroidUtilities.dp(2) : 0);
boolean drawProgress = delegate.shouldDrawThreadProgress(this);
long newTime = SystemClock.elapsedRealtime();
long dt = (newTime - commentProgressLastUpadteTime);
commentProgressLastUpadteTime = newTime;
if (dt > 17) {
dt = 17;
}
if (drawProgress) {
if (commentProgressAlpha < 1.0f) {
commentProgressAlpha += dt / 180.0f;
if (commentProgressAlpha > 1.0f) {
commentProgressAlpha = 1.0f;
}
}
} else {
if (commentProgressAlpha > 0.0f) {
commentProgressAlpha -= dt / 180.0f;
if (commentProgressAlpha < 0.0f) {
commentProgressAlpha = 0.0f;
}
}
}
if ((drawProgress || commentProgressAlpha > 0.0f) && commentProgress != null) {
commentProgress.setColor(getThemedColor(Theme.key_chat_inInstant));
commentProgress.setAlpha(commentProgressAlpha);
commentProgress.draw(canvas, commentX + AndroidUtilities.dp(11), commentY + AndroidUtilities.dp(12), commentProgressAlpha);
invalidate();
}
if (!drawProgress || commentProgressAlpha < 1.0f) {
int aw = Theme.chat_commentArrowDrawable.getIntrinsicWidth();
int ah = Theme.chat_commentArrowDrawable.getIntrinsicHeight();
float acx = commentX + aw / 2;
float acy = commentY + ah / 2;
Theme.chat_commentArrowDrawable.setBounds((int) (acx - aw / 2 * (1.0f - commentProgressAlpha)), (int) (acy - ah / 2 * (1.0f - commentProgressAlpha)), (int) (acx + aw / 2 * (1.0f - commentProgressAlpha)), (int) (acy + ah / 2 * (1.0f - commentProgressAlpha)));
Theme.chat_commentArrowDrawable.setAlpha((int) (255 * (1.0f - commentProgressAlpha) * alpha));
Theme.chat_commentArrowDrawable.draw(canvas);
}
}
}
if (captionLayout == null || selectionOnly && pressedLink == null || (currentMessageObject.deleted && currentPosition != null) || alpha == 0) {
return;
}
if (currentMessageObject.isOutOwner()) {
Theme.chat_msgTextPaint.setColor(getThemedColor(Theme.key_chat_messageTextOut));
Theme.chat_msgTextPaint.linkColor = getThemedColor(Theme.key_chat_messageLinkOut);
} else {
Theme.chat_msgTextPaint.setColor(getThemedColor(Theme.key_chat_messageTextIn));
Theme.chat_msgTextPaint.linkColor = getThemedColor(Theme.key_chat_messageLinkIn);
}
canvas.save();
float renderingAlpha = alpha;
if (currentMessagesGroup != null) {
renderingAlpha = currentMessagesGroup.transitionParams.captionEnterProgress * alpha;
}
if (renderingAlpha == 0) {
return;
}
float captionY = this.captionY;
float captionX = this.captionX;
if (transitionParams.animateBackgroundBoundsInner) {
if (transitionParams.transformGroupToSingleMessage) {
captionY -= getTranslationY();
captionX += transitionParams.deltaLeft;
} else if (transitionParams.moveCaption) {
captionX = this.captionX * transitionParams.animateChangeProgress + transitionParams.captionFromX * (1f - transitionParams.animateChangeProgress);
captionY = this.captionY * transitionParams.animateChangeProgress + transitionParams.captionFromY * (1f - transitionParams.animateChangeProgress);
} else {
captionX += transitionParams.deltaLeft;
}
}
int restore = Integer.MIN_VALUE;
if (renderingAlpha != 1.0f) {
rect.set(captionX, captionY, captionX + captionLayout.getWidth(), captionY + captionLayout.getHeight());
restore = canvas.saveLayerAlpha(rect, (int) (255 * renderingAlpha), Canvas.ALL_SAVE_FLAG);
}
if (transitionParams.animateBackgroundBoundsInner && currentBackgroundDrawable != null && currentMessagesGroup == null) {
Rect r = currentBackgroundDrawable.getBounds();
if (currentMessageObject.isOutOwner() && !mediaBackground && !pinnedBottom) {
canvas.clipRect(getBackgroundDrawableLeft() + transitionParams.deltaLeft + AndroidUtilities.dp(4), getBackgroundDrawableTop() + transitionParams.deltaTop + AndroidUtilities.dp(4), getBackgroundDrawableRight() + transitionParams.deltaRight - AndroidUtilities.dp(10), getBackgroundDrawableBottom() + transitionParams.deltaBottom - AndroidUtilities.dp(4));
} else {
canvas.clipRect(getBackgroundDrawableLeft() + transitionParams.deltaLeft + AndroidUtilities.dp(4), getBackgroundDrawableTop() + transitionParams.deltaTop + AndroidUtilities.dp(4), getBackgroundDrawableRight() + transitionParams.deltaRight - AndroidUtilities.dp(4), getBackgroundDrawableBottom() + transitionParams.deltaBottom - AndroidUtilities.dp(4));
}
}
canvas.translate(captionX, captionY);
if (pressedLink != null) {
for (int b = 0; b < urlPath.size(); b++) {
canvas.drawPath(urlPath.get(b), Theme.chat_urlPaint);
}
}
if (!urlPathSelection.isEmpty()) {
for (int b = 0; b < urlPathSelection.size(); b++) {
canvas.drawPath(urlPathSelection.get(b), Theme.chat_textSearchSelectionPaint);
}
}
if (!selectionOnly) {
try {
if (getDelegate() != null && getDelegate().getTextSelectionHelper() != null && getDelegate().getTextSelectionHelper().isSelected(currentMessageObject)) {
getDelegate().getTextSelectionHelper().drawCaption(currentMessageObject.isOutOwner(), captionLayout, canvas);
}
Emoji.emojiDrawingYOffset = -transitionYOffsetForDrawables;
int spoilersColor = currentMessageObject.isOut() && !ChatObject.isChannelAndNotMegaGroup(currentMessageObject.getChatId(), currentAccount) ? getThemedColor(Theme.key_chat_outTimeText) : captionLayout.getPaint().getColor();
SpoilerEffect.renderWithRipple(this, invalidateSpoilersParent, spoilersColor, 0, captionPatchedSpoilersLayout, captionLayout, captionSpoilers, canvas);
Emoji.emojiDrawingYOffset = 0;
} catch (Exception e) {
FileLog.e(e);
}
}
if (restore != Integer.MIN_VALUE) {
canvas.restoreToCount(restore);
}
canvas.restore();
}
Aggregations