Search in sources :

Example 1 with IdenticonDrawable

use of org.telegram.ui.Components.IdenticonDrawable in project Telegram-FOSS by Telegram-FOSS-Team.

the class IdenticonActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("EncryptionKey", R.string.EncryptionKey));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    fragmentView = new FrameLayout(context);
    FrameLayout parentFrameLayout = (FrameLayout) fragmentView;
    fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    fragmentView.setOnTouchListener((v, event) -> true);
    linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setWeightSum(100);
    parentFrameLayout.addView(linearLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    FrameLayout frameLayout = new FrameLayout(context);
    frameLayout.setPadding(AndroidUtilities.dp(20), AndroidUtilities.dp(20), AndroidUtilities.dp(20), AndroidUtilities.dp(20));
    linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 50.0f));
    ImageView identiconView = new ImageView(context);
    identiconView.setScaleType(ImageView.ScaleType.FIT_XY);
    frameLayout.addView(identiconView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    container = new FrameLayout(context) {

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);
            if (codeTextView != null) {
                int x = codeTextView.getLeft() + codeTextView.getMeasuredWidth() / 2 - emojiTextView.getMeasuredWidth() / 2;
                int y = (codeTextView.getMeasuredHeight() - emojiTextView.getMeasuredHeight()) / 2 + linearLayout1.getTop() - AndroidUtilities.dp(16);
                emojiTextView.layout(x, y, x + emojiTextView.getMeasuredWidth(), y + emojiTextView.getMeasuredHeight());
            }
        }
    };
    container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    linearLayout.addView(container, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 50.0f));
    linearLayout1 = new LinearLayout(context);
    linearLayout1.setOrientation(LinearLayout.VERTICAL);
    linearLayout1.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
    container.addView(linearLayout1, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
    codeTextView = new TextView(context);
    codeTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText4));
    codeTextView.setGravity(Gravity.CENTER);
    codeTextView.setTypeface(Typeface.MONOSPACE);
    codeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    /*codeTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                emojiSelected = !emojiSelected;
                updateEmojiButton(true);
                showHint(false);
            }
        });*/
    linearLayout1.addView(codeTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL));
    textView = new TextView(context);
    textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText4));
    textView.setLinkTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkText));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    textView.setLinksClickable(true);
    textView.setClickable(true);
    textView.setGravity(Gravity.CENTER);
    textView.setMovementMethod(new LinkMovementMethodMy());
    linearLayout1.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL));
    emojiTextView = new TextView(context);
    emojiTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText4));
    emojiTextView.setGravity(Gravity.CENTER);
    emojiTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 32);
    container.addView(emojiTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
    TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance(currentAccount).getEncryptedChat(chat_id);
    if (encryptedChat != null) {
        IdenticonDrawable drawable = new IdenticonDrawable();
        identiconView.setImageDrawable(drawable);
        drawable.setEncryptedChat(encryptedChat);
        TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(encryptedChat.user_id);
        SpannableStringBuilder hash = new SpannableStringBuilder();
        StringBuilder emojis = new StringBuilder();
        if (encryptedChat.key_hash.length > 16) {
            String hex = Utilities.bytesToHex(encryptedChat.key_hash);
            for (int a = 0; a < 32; a++) {
                if (a != 0) {
                    if (a % 8 == 0) {
                        hash.append('\n');
                    } else if (a % 4 == 0) {
                        hash.append(' ');
                    }
                }
                hash.append(hex.substring(a * 2, a * 2 + 2));
                hash.append(' ');
            }
            hash.append("\n");
            for (int a = 0; a < 5; a++) {
                int num = ((encryptedChat.key_hash[16 + a * 4] & 0x7f) << 24) | ((encryptedChat.key_hash[16 + a * 4 + 1] & 0xff) << 16) | ((encryptedChat.key_hash[16 + a * 4 + 2] & 0xff) << 8) | (encryptedChat.key_hash[16 + a * 4 + 3] & 0xff);
                if (a != 0) {
                    emojis.append(" ");
                }
                emojis.append(EmojiData.emojiSecret[num % EmojiData.emojiSecret.length]);
            }
            emojiText = emojis.toString();
        }
        codeTextView.setText(hash.toString());
        hash.clear();
        hash.append(AndroidUtilities.replaceTags(LocaleController.formatString("EncryptionKeyDescription", R.string.EncryptionKeyDescription, user.first_name, user.first_name)));
        final String url = "telegram.org";
        int index = hash.toString().indexOf(url);
        if (index != -1) {
            hash.setSpan(new URLSpanReplacement(LocaleController.getString("EncryptionKeyLink", R.string.EncryptionKeyLink)), index, index + url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        textView.setText(hash);
    }
    updateEmojiButton(false);
    return fragmentView;
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) IdenticonDrawable(org.telegram.ui.Components.IdenticonDrawable) TLRPC(org.telegram.tgnet.TLRPC) FrameLayout(android.widget.FrameLayout) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ActionBar(org.telegram.ui.ActionBar.ActionBar) LinearLayout(android.widget.LinearLayout) SpannableStringBuilder(android.text.SpannableStringBuilder) URLSpanReplacement(org.telegram.ui.Components.URLSpanReplacement)

Aggregations

SpannableStringBuilder (android.text.SpannableStringBuilder)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 TLRPC (org.telegram.tgnet.TLRPC)1 ActionBar (org.telegram.ui.ActionBar.ActionBar)1 IdenticonDrawable (org.telegram.ui.Components.IdenticonDrawable)1 URLSpanReplacement (org.telegram.ui.Components.URLSpanReplacement)1