Java Code Examples for org.telegram.messenger.MessageObject#TextLayoutBlock

The following examples show how to use org.telegram.messenger.MessageObject#TextLayoutBlock . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextSelectionHelper.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public void setMessageObject(ChatMessageCell chatMessageCell) {
    this.maybeSelectedView = chatMessageCell;
    MessageObject messageObject = chatMessageCell.getMessageObject();

    if (maybeIsDescription && chatMessageCell.getDescriptionlayout() != null) {
        textArea.set(
                maybeTextX, maybeTextY,
                maybeTextX + chatMessageCell.getDescriptionlayout().getWidth(),
                maybeTextY + chatMessageCell.getDescriptionlayout().getHeight()
        );
    } else if (chatMessageCell.hasCaptionLayout()) {
        textArea.set(maybeTextX, maybeTextY,
                maybeTextX + chatMessageCell.getCaptionLayout().getWidth(),
                maybeTextY + chatMessageCell.getCaptionLayout().getHeight());
    } else if (messageObject != null && messageObject.textLayoutBlocks.size() > 0) {
        MessageObject.TextLayoutBlock block = messageObject.textLayoutBlocks.get(messageObject.textLayoutBlocks.size() - 1);
        textArea.set(
                maybeTextX, maybeTextY,
                maybeTextX + block.textLayout.getWidth(),
                (int) (maybeTextY + block.textYOffset + block.textLayout.getHeight())
        );
    }
}
 
Example 2
Source File: TextSelectionHelper.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void setMessageObject(ChatMessageCell chatMessageCell) {
    this.maybeSelectedView = chatMessageCell;
    MessageObject messageObject = chatMessageCell.getMessageObject();

    if (maybeIsDescription && chatMessageCell.getDescriptionlayout() != null) {
        textArea.set(
                maybeTextX, maybeTextY,
                maybeTextX + chatMessageCell.getDescriptionlayout().getWidth(),
                maybeTextY + chatMessageCell.getDescriptionlayout().getHeight()
        );
    } else if (chatMessageCell.hasCaptionLayout()) {
        textArea.set(maybeTextX, maybeTextY,
                maybeTextX + chatMessageCell.getCaptionLayout().getWidth(),
                maybeTextY + chatMessageCell.getCaptionLayout().getHeight());
    } else if (messageObject != null && messageObject.textLayoutBlocks.size() > 0) {
        MessageObject.TextLayoutBlock block = messageObject.textLayoutBlocks.get(messageObject.textLayoutBlocks.size() - 1);
        textArea.set(
                maybeTextX, maybeTextY,
                maybeTextX + block.textLayout.getWidth(),
                (int) (maybeTextY + block.textYOffset + block.textLayout.getHeight())
        );
    }
}
 
Example 3
Source File: TextSelectionHelper.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void draw(MessageObject messageObject, MessageObject.TextLayoutBlock block, Canvas canvas) {
    if (selectedView == null || selectedView.getMessageObject() == null || isDescription) {
        return;
    }

    MessageObject selectedMessageObject = selectedView.getMessageObject();
    if (selectedMessageObject == null || selectedMessageObject.textLayoutBlocks == null) {
        return;
    }

    if (messageObject.getId() == selectedCellId) {
        int selectionStart = this.selectionStart;
        int selectionEnd = this.selectionEnd;
        if (selectedMessageObject.textLayoutBlocks.size() > 1) {
            if (selectionStart < block.charactersOffset) {
                selectionStart = block.charactersOffset;
            }
            if (selectionStart > block.charactersEnd) {
                selectionStart = block.charactersEnd;
            }
            if (selectionEnd < block.charactersOffset) {
                selectionEnd = block.charactersOffset;
            }
            if (selectionEnd > block.charactersEnd) {
                selectionEnd = block.charactersEnd;
            }
        }

        if (selectionStart != selectionEnd) {
            if (selectedMessageObject.isOutOwner()) {
                selectionPaint.setColor(Theme.getColor(Theme.key_chat_outTextSelectionHighlight));
            } else {
                selectionPaint.setColor(Theme.getColor(key_chat_inTextSelectionHighlight));
            }
            drawSelection(canvas, block.textLayout, selectionStart, selectionEnd);
        }
    }
}
 
Example 4
Source File: TextSelectionHelper.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void fillLayoutForCoords(int x, int y, ChatMessageCell cell, LayoutBlock layoutBlock, boolean maybe) {
    if (cell == null) {
        return;
    }

    MessageObject messageObject = cell.getMessageObject();

    if (maybe ? maybeIsDescription : isDescription) {
        layoutBlock.layout = cell.getDescriptionlayout();
        layoutBlock.yOffset = layoutBlock.xOffset = 0;
        return;
    }
    if (cell.hasCaptionLayout()) {
        layoutBlock.layout = cell.getCaptionLayout();
        layoutBlock.yOffset = layoutBlock.xOffset = 0;
        return;
    }

    for (int i = 0; i < messageObject.textLayoutBlocks.size(); i++) {
        MessageObject.TextLayoutBlock block = messageObject.textLayoutBlocks.get(i);
        if (y >= block.textYOffset && y <= block.textYOffset + block.height) {
            layoutBlock.layout = block.textLayout;
            layoutBlock.yOffset = block.textYOffset;
            layoutBlock.xOffset = -(block.isRtl() ? (int) Math.ceil(messageObject.textXOffset) : 0);
            return;
        }
    }
}
 
Example 5
Source File: TextSelectionHelper.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void draw(MessageObject messageObject, MessageObject.TextLayoutBlock block, Canvas canvas) {
    if (selectedView == null || selectedView.getMessageObject() == null || isDescription) {
        return;
    }

    MessageObject selectedMessageObject = selectedView.getMessageObject();
    if (selectedMessageObject == null || selectedMessageObject.textLayoutBlocks == null) {
        return;
    }

    if (messageObject.getId() == selectedCellId) {
        int selectionStart = this.selectionStart;
        int selectionEnd = this.selectionEnd;
        if (selectedMessageObject.textLayoutBlocks.size() > 1) {
            if (selectionStart < block.charactersOffset) {
                selectionStart = block.charactersOffset;
            }
            if (selectionStart > block.charactersEnd) {
                selectionStart = block.charactersEnd;
            }
            if (selectionEnd < block.charactersOffset) {
                selectionEnd = block.charactersOffset;
            }
            if (selectionEnd > block.charactersEnd) {
                selectionEnd = block.charactersEnd;
            }
        }

        if (selectionStart != selectionEnd) {
            if (selectedMessageObject.isOutOwner()) {
                selectionPaint.setColor(Theme.getColor(Theme.key_chat_outTextSelectionHighlight));
            } else {
                selectionPaint.setColor(Theme.getColor(key_chat_inTextSelectionHighlight));
            }
            drawSelection(canvas, block.textLayout, selectionStart, selectionEnd);
        }
    }
}
 
Example 6
Source File: TextSelectionHelper.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void fillLayoutForCoords(int x, int y, ChatMessageCell cell, LayoutBlock layoutBlock, boolean maybe) {
    if (cell == null) {
        return;
    }

    MessageObject messageObject = cell.getMessageObject();

    if (maybe ? maybeIsDescription : isDescription) {
        layoutBlock.layout = cell.getDescriptionlayout();
        layoutBlock.yOffset = layoutBlock.xOffset = 0;
        return;
    }
    if (cell.hasCaptionLayout()) {
        layoutBlock.layout = cell.getCaptionLayout();
        layoutBlock.yOffset = layoutBlock.xOffset = 0;
        return;
    }

    for (int i = 0; i < messageObject.textLayoutBlocks.size(); i++) {
        MessageObject.TextLayoutBlock block = messageObject.textLayoutBlocks.get(i);
        if (y >= block.textYOffset && y <= block.textYOffset + block.height) {
            layoutBlock.layout = block.textLayout;
            layoutBlock.yOffset = block.textYOffset;
            layoutBlock.xOffset = -(block.isRtl() ? (int) Math.ceil(messageObject.textXOffset) : 0);
            return;
        }
    }
}
 
Example 7
Source File: TextSelectionHelper.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void fillLayoutForOffset(int offset, LayoutBlock layoutBlock, boolean maybe) {
    ChatMessageCell selectedView = maybe ? maybeSelectedView : this.selectedView;
    if (selectedView == null) {
        layoutBlock.layout = null;
        return;
    }
    MessageObject messageObject = selectedView.getMessageObject();

    if (isDescription) {
        layoutBlock.layout = selectedView.getDescriptionlayout();
        layoutBlock.xOffset = layoutBlock.yOffset = 0;
        return;
    }

    if (selectedView.hasCaptionLayout()) {
        layoutBlock.layout = selectedView.getCaptionLayout();
        layoutBlock.xOffset = layoutBlock.yOffset = 0;
        return;
    }

    if (messageObject.textLayoutBlocks == null) {
        layoutBlock.layout = null;
        return;
    }

    if (messageObject.textLayoutBlocks.size() == 1) {
        layoutBlock.layout = messageObject.textLayoutBlocks.get(0).textLayout;
        layoutBlock.yOffset = 0;
        layoutBlock.xOffset = -(messageObject.textLayoutBlocks.get(0).isRtl() ? (int) Math.ceil(messageObject.textXOffset) : 0);
        return;
    }

    for (int i = 0; i < messageObject.textLayoutBlocks.size(); i++) {
        MessageObject.TextLayoutBlock block = messageObject.textLayoutBlocks.get(i);
        if (offset >= block.charactersOffset && offset <= block.charactersEnd) {
            layoutBlock.layout = messageObject.textLayoutBlocks.get(i).textLayout;
            layoutBlock.yOffset = messageObject.textLayoutBlocks.get(i).textYOffset;
            layoutBlock.xOffset = -(block.isRtl() ? (int) Math.ceil(messageObject.textXOffset) : 0);
            return;
        }
    }
    layoutBlock.layout = null;
}
 
Example 8
Source File: TextSelectionHelper.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void fillLayoutForOffset(int offset, LayoutBlock layoutBlock, boolean maybe) {
    ChatMessageCell selectedView = maybe ? maybeSelectedView : this.selectedView;
    if (selectedView == null) {
        layoutBlock.layout = null;
        return;
    }
    MessageObject messageObject = selectedView.getMessageObject();

    if (isDescription) {
        layoutBlock.layout = selectedView.getDescriptionlayout();
        layoutBlock.xOffset = layoutBlock.yOffset = 0;
        return;
    }

    if (selectedView.hasCaptionLayout()) {
        layoutBlock.layout = selectedView.getCaptionLayout();
        layoutBlock.xOffset = layoutBlock.yOffset = 0;
        return;
    }

    if (messageObject.textLayoutBlocks == null) {
        layoutBlock.layout = null;
        return;
    }

    if (messageObject.textLayoutBlocks.size() == 1) {
        layoutBlock.layout = messageObject.textLayoutBlocks.get(0).textLayout;
        layoutBlock.yOffset = 0;
        layoutBlock.xOffset = -(messageObject.textLayoutBlocks.get(0).isRtl() ? (int) Math.ceil(messageObject.textXOffset) : 0);
        return;
    }

    for (int i = 0; i < messageObject.textLayoutBlocks.size(); i++) {
        MessageObject.TextLayoutBlock block = messageObject.textLayoutBlocks.get(i);
        if (offset >= block.charactersOffset && offset <= block.charactersEnd) {
            layoutBlock.layout = messageObject.textLayoutBlocks.get(i).textLayout;
            layoutBlock.yOffset = messageObject.textLayoutBlocks.get(i).textYOffset;
            layoutBlock.xOffset = -(block.isRtl() ? (int) Math.ceil(messageObject.textXOffset) : 0);
            return;
        }
    }
    layoutBlock.layout = null;
}