Java Code Examples for org.telegram.tgnet.TLRPC#KeyboardButton

The following examples show how to use org.telegram.tgnet.TLRPC#KeyboardButton . 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: BotKeyboardView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void setButtons(TLRPC.TL_replyKeyboardMarkup buttons) {
    botButtons = buttons;
    container.removeAllViews();
    buttonViews.clear();
    scrollView.scrollTo(0, 0);

    if (buttons != null && botButtons.rows.size() != 0) {
        isFullSize = !buttons.resize;
        buttonHeight = !isFullSize ? 42 : (int) Math.max(42, (panelHeight - AndroidUtilities.dp(30) - (botButtons.rows.size() - 1) * AndroidUtilities.dp(10)) / botButtons.rows.size() / AndroidUtilities.density);
        for (int a = 0; a < buttons.rows.size(); a++) {
            TLRPC.TL_keyboardButtonRow row = buttons.rows.get(a);

            LinearLayout layout = new LinearLayout(getContext());
            layout.setOrientation(LinearLayout.HORIZONTAL);
            container.addView(layout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, buttonHeight, 15, a == 0 ? 15 : 10, 15, a == buttons.rows.size() - 1 ? 15 : 0));

            float weight = 1.0f / row.buttons.size();
            for (int b = 0; b < row.buttons.size(); b++) {
                TLRPC.KeyboardButton button = row.buttons.get(b);
                TextView textView = new TextView(getContext());
                textView.setTag(button);
                textView.setTextColor(Theme.getColor(Theme.key_chat_botKeyboardButtonText));
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
                textView.setGravity(Gravity.CENTER);
                textView.setBackgroundDrawable(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(4), Theme.getColor(Theme.key_chat_botKeyboardButtonBackground), Theme.getColor(Theme.key_chat_botKeyboardButtonBackgroundPressed)));
                textView.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
                textView.setText(Emoji.replaceEmoji(button.text, textView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(16), false));
                layout.addView(textView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, weight, 0, 0, b != row.buttons.size() - 1 ? 10 : 0, 0));
                textView.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        delegate.didPressedButton((TLRPC.KeyboardButton) v.getTag());
                    }
                });
                buttonViews.add(textView);
            }
        }
    }
}
 
Example 2
Source File: BotKeyboardView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void setButtons(TLRPC.TL_replyKeyboardMarkup buttons) {
    botButtons = buttons;
    container.removeAllViews();
    buttonViews.clear();
    scrollView.scrollTo(0, 0);

    if (buttons != null && botButtons.rows.size() != 0) {
        isFullSize = !buttons.resize;
        buttonHeight = !isFullSize ? 42 : (int) Math.max(42, (panelHeight - AndroidUtilities.dp(30) - (botButtons.rows.size() - 1) * AndroidUtilities.dp(10)) / botButtons.rows.size() / AndroidUtilities.density);
        for (int a = 0; a < buttons.rows.size(); a++) {
            TLRPC.TL_keyboardButtonRow row = buttons.rows.get(a);

            LinearLayout layout = new LinearLayout(getContext());
            layout.setOrientation(LinearLayout.HORIZONTAL);
            container.addView(layout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, buttonHeight, 15, a == 0 ? 15 : 10, 15, a == buttons.rows.size() - 1 ? 15 : 0));

            float weight = 1.0f / row.buttons.size();
            for (int b = 0; b < row.buttons.size(); b++) {
                TLRPC.KeyboardButton button = row.buttons.get(b);
                TextView textView = new TextView(getContext());
                textView.setTag(button);
                textView.setTextColor(Theme.getColor(Theme.key_chat_botKeyboardButtonText));
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
                textView.setGravity(Gravity.CENTER);
                textView.setBackgroundDrawable(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(4), Theme.getColor(Theme.key_chat_botKeyboardButtonBackground), Theme.getColor(Theme.key_chat_botKeyboardButtonBackgroundPressed)));
                textView.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
                textView.setText(Emoji.replaceEmoji(button.text, textView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(16), false));
                layout.addView(textView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, weight, 0, 0, b != row.buttons.size() - 1 ? 10 : 0, 0));
                textView.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        delegate.didPressedButton((TLRPC.KeyboardButton) v.getTag());
                    }
                });
                buttonViews.add(textView);
            }
        }
    }
}
 
Example 3
Source File: BotKeyboardView.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void setButtons(TLRPC.TL_replyKeyboardMarkup buttons) {
    botButtons = buttons;
    container.removeAllViews();
    buttonViews.clear();
    scrollView.scrollTo(0, 0);

    if (buttons != null && botButtons.rows.size() != 0) {
        isFullSize = !buttons.resize;
        buttonHeight = !isFullSize ? 42 : (int) Math.max(42, (panelHeight - AndroidUtilities.dp(30) - (botButtons.rows.size() - 1) * AndroidUtilities.dp(10)) / botButtons.rows.size() / AndroidUtilities.density);
        for (int a = 0; a < buttons.rows.size(); a++) {
            TLRPC.TL_keyboardButtonRow row = buttons.rows.get(a);

            LinearLayout layout = new LinearLayout(getContext());
            layout.setOrientation(LinearLayout.HORIZONTAL);
            container.addView(layout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, buttonHeight, 15, a == 0 ? 15 : 10, 15, a == buttons.rows.size() - 1 ? 15 : 0));

            float weight = 1.0f / row.buttons.size();
            for (int b = 0; b < row.buttons.size(); b++) {
                TLRPC.KeyboardButton button = row.buttons.get(b);
                TextView textView = new TextView(getContext());
                textView.setTag(button);
                textView.setTextColor(Theme.getColor(Theme.key_chat_botKeyboardButtonText));
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
                textView.setGravity(Gravity.CENTER);
                textView.setBackgroundDrawable(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(4), Theme.getColor(Theme.key_chat_botKeyboardButtonBackground), Theme.getColor(Theme.key_chat_botKeyboardButtonBackgroundPressed)));
                textView.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
                textView.setText(Emoji.replaceEmoji(button.text, textView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(16), false));
                layout.addView(textView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, weight, 0, 0, b != row.buttons.size() - 1 ? 10 : 0, 0));
                textView.setOnClickListener(v -> delegate.didPressedButton((TLRPC.KeyboardButton) v.getTag()));
                buttonViews.add(textView);
            }
        }
    }
}
 
Example 4
Source File: BotKeyboardView.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void setButtons(TLRPC.TL_replyKeyboardMarkup buttons) {
    botButtons = buttons;
    container.removeAllViews();
    buttonViews.clear();
    scrollView.scrollTo(0, 0);

    if (buttons != null && botButtons.rows.size() != 0) {
        isFullSize = !buttons.resize;
        buttonHeight = !isFullSize ? 42 : (int) Math.max(42, (panelHeight - AndroidUtilities.dp(30) - (botButtons.rows.size() - 1) * AndroidUtilities.dp(10)) / botButtons.rows.size() / AndroidUtilities.density);
        for (int a = 0; a < buttons.rows.size(); a++) {
            TLRPC.TL_keyboardButtonRow row = buttons.rows.get(a);

            LinearLayout layout = new LinearLayout(getContext());
            layout.setOrientation(LinearLayout.HORIZONTAL);
            container.addView(layout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, buttonHeight, 15, a == 0 ? 15 : 10, 15, a == buttons.rows.size() - 1 ? 15 : 0));

            float weight = 1.0f / row.buttons.size();
            for (int b = 0; b < row.buttons.size(); b++) {
                TLRPC.KeyboardButton button = row.buttons.get(b);
                TextView textView = new TextView(getContext());
                textView.setTag(button);
                textView.setTextColor(Theme.getColor(Theme.key_chat_botKeyboardButtonText));
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
                textView.setGravity(Gravity.CENTER);
                textView.setBackgroundDrawable(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(4), Theme.getColor(Theme.key_chat_botKeyboardButtonBackground), Theme.getColor(Theme.key_chat_botKeyboardButtonBackgroundPressed)));
                textView.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
                textView.setText(Emoji.replaceEmoji(button.text, textView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(16), false));
                layout.addView(textView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, weight, 0, 0, b != row.buttons.size() - 1 ? 10 : 0, 0));
                textView.setOnClickListener(v -> delegate.didPressedButton((TLRPC.KeyboardButton) v.getTag()));
                buttonViews.add(textView);
            }
        }
    }
}
 
Example 5
Source File: ChatActionCell.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
default void didPressBotButton(MessageObject messageObject, TLRPC.KeyboardButton button) {
}
 
Example 6
Source File: ChatActionCell.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
default void didPressBotButton(MessageObject messageObject, TLRPC.KeyboardButton button) {
}
 
Example 7
Source File: ChatActionCell.java    From TelePlus-Android with GNU General Public License v2.0 votes vote down vote up
void didPressedBotButton(MessageObject messageObject, TLRPC.KeyboardButton button); 
Example 8
Source File: BotKeyboardView.java    From TelePlus-Android with GNU General Public License v2.0 votes vote down vote up
void didPressedButton(TLRPC.KeyboardButton button); 
Example 9
Source File: ChatActionCell.java    From TelePlus-Android with GNU General Public License v2.0 votes vote down vote up
void didPressedBotButton(MessageObject messageObject, TLRPC.KeyboardButton button); 
Example 10
Source File: BotKeyboardView.java    From TelePlus-Android with GNU General Public License v2.0 votes vote down vote up
void didPressedButton(TLRPC.KeyboardButton button); 
Example 11
Source File: BotKeyboardView.java    From Telegram-FOSS with GNU General Public License v2.0 votes vote down vote up
void didPressedButton(TLRPC.KeyboardButton button); 
Example 12
Source File: BotKeyboardView.java    From Telegram with GNU General Public License v2.0 votes vote down vote up
void didPressedButton(TLRPC.KeyboardButton button);