Search in sources :

Example 21 with EditTextBoldCursor

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

the class ChatEditTypeActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                processDone();
            }
        }
    });
    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56), LocaleController.getString("Done", R.string.Done));
    fragmentView = new ScrollView(context) {

        @Override
        public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
            rectangle.bottom += AndroidUtilities.dp(60);
            return super.requestChildRectangleOnScreen(child, rectangle, immediate);
        }
    };
    fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    ScrollView scrollView = (ScrollView) fragmentView;
    scrollView.setFillViewport(true);
    linearLayout = new LinearLayout(context);
    scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    if (isForcePublic) {
        actionBar.setTitle(LocaleController.getString("TypeLocationGroup", R.string.TypeLocationGroup));
    } else if (isChannel) {
        actionBar.setTitle(LocaleController.getString("ChannelSettingsTitle", R.string.ChannelSettingsTitle));
    } else {
        actionBar.setTitle(LocaleController.getString("GroupSettingsTitle", R.string.GroupSettingsTitle));
    }
    linearLayoutTypeContainer = new LinearLayout(context);
    linearLayoutTypeContainer.setOrientation(LinearLayout.VERTICAL);
    linearLayoutTypeContainer.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    linearLayout.addView(linearLayoutTypeContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    headerCell2 = new HeaderCell(context, 23);
    headerCell2.setHeight(46);
    if (isChannel) {
        headerCell2.setText(LocaleController.getString("ChannelTypeHeader", R.string.ChannelTypeHeader));
    } else {
        headerCell2.setText(LocaleController.getString("GroupTypeHeader", R.string.GroupTypeHeader));
    }
    linearLayoutTypeContainer.addView(headerCell2);
    radioButtonCell2 = new RadioButtonCell(context);
    radioButtonCell2.setBackgroundDrawable(Theme.getSelectorDrawable(false));
    if (isChannel) {
        radioButtonCell2.setTextAndValue(LocaleController.getString("ChannelPrivate", R.string.ChannelPrivate), LocaleController.getString("ChannelPrivateInfo", R.string.ChannelPrivateInfo), false, isPrivate);
    } else {
        radioButtonCell2.setTextAndValue(LocaleController.getString("MegaPrivate", R.string.MegaPrivate), LocaleController.getString("MegaPrivateInfo", R.string.MegaPrivateInfo), false, isPrivate);
    }
    linearLayoutTypeContainer.addView(radioButtonCell2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    radioButtonCell2.setOnClickListener(v -> {
        if (isPrivate) {
            return;
        }
        isPrivate = true;
        updatePrivatePublic();
    });
    radioButtonCell1 = new RadioButtonCell(context);
    radioButtonCell1.setBackgroundDrawable(Theme.getSelectorDrawable(false));
    if (isChannel) {
        radioButtonCell1.setTextAndValue(LocaleController.getString("ChannelPublic", R.string.ChannelPublic), LocaleController.getString("ChannelPublicInfo", R.string.ChannelPublicInfo), false, !isPrivate);
    } else {
        radioButtonCell1.setTextAndValue(LocaleController.getString("MegaPublic", R.string.MegaPublic), LocaleController.getString("MegaPublicInfo", R.string.MegaPublicInfo), false, !isPrivate);
    }
    linearLayoutTypeContainer.addView(radioButtonCell1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    radioButtonCell1.setOnClickListener(v -> {
        if (!isPrivate) {
            return;
        }
        isPrivate = false;
        updatePrivatePublic();
    });
    sectionCell2 = new ShadowSectionCell(context);
    linearLayout.addView(sectionCell2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    if (isForcePublic) {
        radioButtonCell2.setVisibility(View.GONE);
        radioButtonCell1.setVisibility(View.GONE);
        sectionCell2.setVisibility(View.GONE);
        headerCell2.setVisibility(View.GONE);
    }
    linkContainer = new LinearLayout(context);
    linkContainer.setOrientation(LinearLayout.VERTICAL);
    linkContainer.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    linearLayout.addView(linkContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    headerCell = new HeaderCell(context, 23);
    linkContainer.addView(headerCell);
    publicContainer = new LinearLayout(context);
    publicContainer.setOrientation(LinearLayout.HORIZONTAL);
    linkContainer.addView(publicContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 23, 7, 23, 0));
    editText = new EditTextBoldCursor(context);
    editText.setText(getMessagesController().linkPrefix + "/");
    editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    editText.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
    editText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    editText.setMaxLines(1);
    editText.setLines(1);
    editText.setEnabled(false);
    editText.setBackgroundDrawable(null);
    editText.setPadding(0, 0, 0, 0);
    editText.setSingleLine(true);
    editText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    publicContainer.addView(editText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 36));
    usernameTextView = new EditTextBoldCursor(context);
    usernameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    usernameTextView.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
    usernameTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    usernameTextView.setMaxLines(1);
    usernameTextView.setLines(1);
    usernameTextView.setBackgroundDrawable(null);
    usernameTextView.setPadding(0, 0, 0, 0);
    usernameTextView.setSingleLine(true);
    usernameTextView.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    usernameTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
    usernameTextView.setHint(LocaleController.getString("ChannelUsernamePlaceholder", R.string.ChannelUsernamePlaceholder));
    usernameTextView.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    usernameTextView.setCursorSize(AndroidUtilities.dp(20));
    usernameTextView.setCursorWidth(1.5f);
    publicContainer.addView(usernameTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36));
    usernameTextView.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            if (ignoreTextChanges) {
                return;
            }
            checkUserName(usernameTextView.getText().toString());
        }

        @Override
        public void afterTextChanged(Editable editable) {
            checkDoneButton();
        }
    });
    privateContainer = new LinearLayout(context);
    privateContainer.setOrientation(LinearLayout.VERTICAL);
    linkContainer.addView(privateContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    permanentLinkView = new LinkActionView(context, this, null, chatId, true, ChatObject.isChannel(currentChat));
    permanentLinkView.setDelegate(new LinkActionView.Delegate() {

        @Override
        public void revokeLink() {
            ChatEditTypeActivity.this.generateLink(true);
        }

        @Override
        public void showUsersForPermanentLink() {
            inviteLinkBottomSheet = new InviteLinkBottomSheet(context, invite, info, usersMap, ChatEditTypeActivity.this, chatId, true, ChatObject.isChannel(currentChat));
            inviteLinkBottomSheet.show();
        }
    });
    permanentLinkView.setUsers(0, null);
    privateContainer.addView(permanentLinkView);
    checkTextView = new TextInfoPrivacyCell(context);
    checkTextView.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
    checkTextView.setBottomPadding(6);
    linearLayout.addView(checkTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
    typeInfoCell = new TextInfoPrivacyCell(context);
    linearLayout.addView(typeInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    loadingAdminedCell = new LoadingCell(context);
    linearLayout.addView(loadingAdminedCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    adminnedChannelsLayout = new LinearLayout(context);
    adminnedChannelsLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    adminnedChannelsLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.addView(adminnedChannelsLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    adminedInfoCell = new ShadowSectionCell(context);
    linearLayout.addView(adminedInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    manageLinksTextView = new TextCell(context);
    manageLinksTextView.setBackgroundDrawable(Theme.getSelectorDrawable(true));
    manageLinksTextView.setTextAndIcon(LocaleController.getString("ManageInviteLinks", R.string.ManageInviteLinks), R.drawable.actions_link, false);
    manageLinksTextView.setOnClickListener(v -> {
        ManageLinksActivity fragment = new ManageLinksActivity(chatId, 0, 0);
        fragment.setInfo(info, invite);
        presentFragment(fragment);
    });
    linearLayout.addView(manageLinksTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    manageLinksInfoCell = new TextInfoPrivacyCell(context);
    linearLayout.addView(manageLinksInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    saveContainer = new LinearLayout(context);
    saveContainer.setOrientation(LinearLayout.VERTICAL);
    linearLayout.addView(saveContainer);
    saveHeaderCell = new HeaderCell(context, 23);
    saveHeaderCell.setHeight(46);
    saveHeaderCell.setText(LocaleController.getString("SavingContentTitle", R.string.SavingContentTitle));
    saveHeaderCell.setBackgroundDrawable(Theme.getSelectorDrawable(true));
    saveContainer.addView(saveHeaderCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    saveRestrictCell = new TextCheckCell(context);
    saveRestrictCell.setBackgroundDrawable(Theme.getSelectorDrawable(true));
    saveRestrictCell.setTextAndCheck(LocaleController.getString("RestrictSavingContent", R.string.RestrictSavingContent), isSaveRestricted, false);
    saveRestrictCell.setOnClickListener(v -> {
        isSaveRestricted = !isSaveRestricted;
        ((TextCheckCell) v).setChecked(isSaveRestricted);
    });
    saveContainer.addView(saveRestrictCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    saveRestrictInfoCell = new TextInfoPrivacyCell(context);
    if (isChannel && !ChatObject.isMegagroup(currentChat)) {
        saveRestrictInfoCell.setText(LocaleController.getString("RestrictSavingContentInfoChannel", R.string.RestrictSavingContentInfoChannel));
    } else {
        saveRestrictInfoCell.setText(LocaleController.getString("RestrictSavingContentInfoGroup", R.string.RestrictSavingContentInfoGroup));
    }
    saveContainer.addView(saveRestrictInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    if (!isPrivate && currentChat.username != null) {
        ignoreTextChanges = true;
        usernameTextView.setText(currentChat.username);
        usernameTextView.setSelection(currentChat.username.length());
        ignoreTextChanges = false;
    }
    updatePrivatePublic();
    return fragmentView;
}
Also used : RadioButtonCell(org.telegram.ui.Cells.RadioButtonCell) LinkActionView(org.telegram.ui.Components.LinkActionView) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) HeaderCell(org.telegram.ui.Cells.HeaderCell) TextCell(org.telegram.ui.Cells.TextCell) LoadingCell(org.telegram.ui.Cells.LoadingCell) InviteLinkBottomSheet(org.telegram.ui.Components.InviteLinkBottomSheet) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) ActionBar(org.telegram.ui.ActionBar.ActionBar) Rect(android.graphics.Rect) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) LinkActionView(org.telegram.ui.Components.LinkActionView) View(android.view.View) ScrollView(android.widget.ScrollView) ScrollView(android.widget.ScrollView) LinearLayout(android.widget.LinearLayout)

Example 22 with EditTextBoldCursor

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

the class ChannelCreateActivity method createView.

@Override
public View createView(Context context) {
    if (nameTextView != null) {
        nameTextView.onDestroy();
    }
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (currentStep == 0) {
                    if (donePressed || getParentActivity() == null) {
                        return;
                    }
                    if (nameTextView.length() == 0) {
                        Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
                        if (v != null) {
                            v.vibrate(200);
                        }
                        AndroidUtilities.shakeView(nameTextView, 2, 0);
                        return;
                    }
                    donePressed = true;
                    if (imageUpdater.isUploadingImage()) {
                        createAfterUpload = true;
                        progressDialog = new AlertDialog(getParentActivity(), 3);
                        progressDialog.setOnCancelListener(dialog -> {
                            createAfterUpload = false;
                            progressDialog = null;
                            donePressed = false;
                        });
                        progressDialog.show();
                        return;
                    }
                    final int reqId = MessagesController.getInstance(currentAccount).createChat(nameTextView.getText().toString(), new ArrayList<>(), descriptionTextView.getText().toString(), ChatObject.CHAT_TYPE_CHANNEL, false, null, null, ChannelCreateActivity.this);
                    progressDialog = new AlertDialog(getParentActivity(), 3);
                    progressDialog.setOnCancelListener(dialog -> {
                        ConnectionsManager.getInstance(currentAccount).cancelRequest(reqId, true);
                        donePressed = false;
                    });
                    progressDialog.show();
                } else if (currentStep == 1) {
                    if (!isPrivate) {
                        if (descriptionTextView.length() == 0) {
                            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                            builder.setTitle(LocaleController.getString("ChannelPublicEmptyUsernameTitle", R.string.ChannelPublicEmptyUsernameTitle));
                            builder.setMessage(LocaleController.getString("ChannelPublicEmptyUsername", R.string.ChannelPublicEmptyUsername));
                            builder.setPositiveButton(LocaleController.getString("Close", R.string.Close), null);
                            showDialog(builder.create());
                            return;
                        } else {
                            if (!lastNameAvailable) {
                                Vibrator v = (Vibrator) getParentActivity().getSystemService(Context.VIBRATOR_SERVICE);
                                if (v != null) {
                                    v.vibrate(200);
                                }
                                AndroidUtilities.shakeView(checkTextView, 2, 0);
                                return;
                            } else {
                                MessagesController.getInstance(currentAccount).updateChannelUserName(chatId, lastCheckName);
                            }
                        }
                    }
                    Bundle args = new Bundle();
                    args.putInt("step", 2);
                    args.putLong("chatId", chatId);
                    args.putInt("chatType", ChatObject.CHAT_TYPE_CHANNEL);
                    presentFragment(new GroupCreateActivity(args), true);
                }
            }
        }
    });
    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56), LocaleController.getString("Done", R.string.Done));
    if (currentStep == 0) {
        actionBar.setTitle(LocaleController.getString("NewChannel", R.string.NewChannel));
        SizeNotifierFrameLayout sizeNotifierFrameLayout = new SizeNotifierFrameLayout(context) {

            private boolean ignoreLayout;

            @Override
            protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                int widthSize = MeasureSpec.getSize(widthMeasureSpec);
                int heightSize = MeasureSpec.getSize(heightMeasureSpec);
                setMeasuredDimension(widthSize, heightSize);
                heightSize -= getPaddingTop();
                measureChildWithMargins(actionBar, widthMeasureSpec, 0, heightMeasureSpec, 0);
                int keyboardSize = measureKeyboardHeight();
                if (keyboardSize > AndroidUtilities.dp(20)) {
                    ignoreLayout = true;
                    nameTextView.hideEmojiView();
                    ignoreLayout = false;
                }
                int childCount = getChildCount();
                for (int i = 0; i < childCount; i++) {
                    View child = getChildAt(i);
                    if (child == null || child.getVisibility() == GONE || child == actionBar) {
                        continue;
                    }
                    if (nameTextView != null && nameTextView.isPopupView(child)) {
                        if (AndroidUtilities.isInMultiwindow || AndroidUtilities.isTablet()) {
                            if (AndroidUtilities.isTablet()) {
                                child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(Math.min(AndroidUtilities.dp(AndroidUtilities.isTablet() ? 200 : 320), heightSize - AndroidUtilities.statusBarHeight + getPaddingTop()), MeasureSpec.EXACTLY));
                            } else {
                                child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize - AndroidUtilities.statusBarHeight + getPaddingTop(), MeasureSpec.EXACTLY));
                            }
                        } else {
                            child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(child.getLayoutParams().height, MeasureSpec.EXACTLY));
                        }
                    } else {
                        measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
                    }
                }
            }

            @Override
            protected void onLayout(boolean changed, int l, int t, int r, int b) {
                final int count = getChildCount();
                int keyboardSize = measureKeyboardHeight();
                int paddingBottom = keyboardSize <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow && !AndroidUtilities.isTablet() ? nameTextView.getEmojiPadding() : 0;
                setBottomClip(paddingBottom);
                for (int i = 0; i < count; i++) {
                    final View child = getChildAt(i);
                    if (child.getVisibility() == GONE) {
                        continue;
                    }
                    final LayoutParams lp = (LayoutParams) child.getLayoutParams();
                    final int width = child.getMeasuredWidth();
                    final int height = child.getMeasuredHeight();
                    int childLeft;
                    int childTop;
                    int gravity = lp.gravity;
                    if (gravity == -1) {
                        gravity = Gravity.TOP | Gravity.LEFT;
                    }
                    final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                    final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
                    switch(absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                        case Gravity.CENTER_HORIZONTAL:
                            childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin;
                            break;
                        case Gravity.RIGHT:
                            childLeft = r - width - lp.rightMargin;
                            break;
                        case Gravity.LEFT:
                        default:
                            childLeft = lp.leftMargin;
                    }
                    switch(verticalGravity) {
                        case Gravity.TOP:
                            childTop = lp.topMargin + getPaddingTop();
                            break;
                        case Gravity.CENTER_VERTICAL:
                            childTop = ((b - paddingBottom) - t - height) / 2 + lp.topMargin - lp.bottomMargin;
                            break;
                        case Gravity.BOTTOM:
                            childTop = ((b - paddingBottom) - t) - height - lp.bottomMargin;
                            break;
                        default:
                            childTop = lp.topMargin;
                    }
                    if (nameTextView != null && nameTextView.isPopupView(child)) {
                        if (AndroidUtilities.isTablet()) {
                            childTop = getMeasuredHeight() - child.getMeasuredHeight();
                        } else {
                            childTop = getMeasuredHeight() + keyboardSize - child.getMeasuredHeight();
                        }
                    }
                    child.layout(childLeft, childTop, childLeft + width, childTop + height);
                }
                notifyHeightChanged();
            }

            @Override
            public void requestLayout() {
                if (ignoreLayout) {
                    return;
                }
                super.requestLayout();
            }
        };
        sizeNotifierFrameLayout.setOnTouchListener((v, event) -> true);
        fragmentView = sizeNotifierFrameLayout;
        fragmentView.setTag(Theme.key_windowBackgroundWhite);
        fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        linearLayout = new LinearLayout(context);
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        sizeNotifierFrameLayout.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        FrameLayout frameLayout = new FrameLayout(context);
        linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        avatarImage = new BackupImageView(context) {

            @Override
            public void invalidate() {
                if (avatarOverlay != null) {
                    avatarOverlay.invalidate();
                }
                super.invalidate();
            }

            @Override
            public void invalidate(int l, int t, int r, int b) {
                if (avatarOverlay != null) {
                    avatarOverlay.invalidate();
                }
                super.invalidate(l, t, r, b);
            }
        };
        avatarImage.setRoundRadius(AndroidUtilities.dp(32));
        avatarDrawable.setInfo(5, null, null);
        avatarImage.setImageDrawable(avatarDrawable);
        frameLayout.addView(avatarImage, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 12));
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(0x55000000);
        avatarOverlay = new View(context) {

            @Override
            protected void onDraw(Canvas canvas) {
                if (avatarImage != null && avatarImage.getImageReceiver().hasNotThumb()) {
                    paint.setAlpha((int) (0x55 * avatarImage.getImageReceiver().getCurrentAlpha()));
                    canvas.drawCircle(getMeasuredWidth() / 2.0f, getMeasuredHeight() / 2.0f, getMeasuredWidth() / 2.0f, paint);
                }
            }
        };
        frameLayout.addView(avatarOverlay, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 12));
        avatarOverlay.setOnClickListener(view -> {
            imageUpdater.openMenu(avatar != null, () -> {
                avatar = null;
                avatarBig = null;
                inputPhoto = null;
                inputVideo = null;
                inputVideoPath = null;
                videoTimestamp = 0;
                showAvatarProgress(false, true);
                avatarImage.setImage(null, null, avatarDrawable, null);
                avatarEditor.setAnimation(cameraDrawable);
                cameraDrawable.setCurrentFrame(0);
            }, dialog -> {
                if (!imageUpdater.isUploadingImage()) {
                    cameraDrawable.setCustomEndFrame(86);
                    avatarEditor.playAnimation();
                } else {
                    cameraDrawable.setCurrentFrame(0, false);
                }
            });
            cameraDrawable.setCurrentFrame(0);
            cameraDrawable.setCustomEndFrame(43);
            avatarEditor.playAnimation();
        });
        cameraDrawable = new RLottieDrawable(R.raw.camera, "" + R.raw.camera, AndroidUtilities.dp(60), AndroidUtilities.dp(60), false, null);
        avatarEditor = new RLottieImageView(context) {

            @Override
            public void invalidate(int l, int t, int r, int b) {
                super.invalidate(l, t, r, b);
                avatarOverlay.invalidate();
            }

            @Override
            public void invalidate() {
                super.invalidate();
                avatarOverlay.invalidate();
            }
        };
        avatarEditor.setScaleType(ImageView.ScaleType.CENTER);
        avatarEditor.setAnimation(cameraDrawable);
        avatarEditor.setEnabled(false);
        avatarEditor.setClickable(false);
        avatarEditor.setPadding(AndroidUtilities.dp(2), 0, 0, AndroidUtilities.dp(1));
        frameLayout.addView(avatarEditor, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 12));
        avatarProgressView = new RadialProgressView(context);
        avatarProgressView.setSize(AndroidUtilities.dp(30));
        avatarProgressView.setProgressColor(0xffffffff);
        avatarProgressView.setNoProgress(false);
        frameLayout.addView(avatarProgressView, LayoutHelper.createFrame(64, 64, Gravity.TOP | (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT), LocaleController.isRTL ? 0 : 16, 12, LocaleController.isRTL ? 16 : 0, 12));
        showAvatarProgress(false, false);
        nameTextView = new EditTextEmoji(context, sizeNotifierFrameLayout, this, EditTextEmoji.STYLE_FRAGMENT);
        nameTextView.setHint(LocaleController.getString("EnterChannelName", R.string.EnterChannelName));
        if (nameToSet != null) {
            nameTextView.setText(nameToSet);
            nameToSet = null;
        }
        InputFilter[] inputFilters = new InputFilter[1];
        inputFilters[0] = new InputFilter.LengthFilter(100);
        nameTextView.setFilters(inputFilters);
        nameTextView.getEditText().setSingleLine(true);
        nameTextView.getEditText().setImeOptions(EditorInfo.IME_ACTION_NEXT);
        nameTextView.getEditText().setOnEditorActionListener((textView, i, keyEvent) -> {
            if (i == EditorInfo.IME_ACTION_NEXT && !TextUtils.isEmpty(nameTextView.getEditText().getText())) {
                descriptionTextView.requestFocus();
                return true;
            }
            return false;
        });
        frameLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 5 : 96, 0, LocaleController.isRTL ? 96 : 5, 0));
        descriptionTextView = new EditTextBoldCursor(context);
        descriptionTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        descriptionTextView.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
        descriptionTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        descriptionTextView.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
        descriptionTextView.setPadding(0, 0, 0, AndroidUtilities.dp(6));
        descriptionTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
        descriptionTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
        descriptionTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
        inputFilters = new InputFilter[1];
        inputFilters[0] = new InputFilter.LengthFilter(120);
        descriptionTextView.setFilters(inputFilters);
        descriptionTextView.setHint(LocaleController.getString("DescriptionPlaceholder", R.string.DescriptionPlaceholder));
        descriptionTextView.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        descriptionTextView.setCursorSize(AndroidUtilities.dp(20));
        descriptionTextView.setCursorWidth(1.5f);
        linearLayout.addView(descriptionTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 24, 18, 24, 0));
        descriptionTextView.setOnEditorActionListener((textView, i, keyEvent) -> {
            if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
                doneButton.performClick();
                return true;
            }
            return false;
        });
        descriptionTextView.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
            }
        });
        helpTextView = new TextView(context);
        helpTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
        helpTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText8));
        helpTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
        helpTextView.setText(LocaleController.getString("DescriptionInfo", R.string.DescriptionInfo));
        linearLayout.addView(helpTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 24, 10, 24, 20));
    } else if (currentStep == 1) {
        fragmentView = new ScrollView(context);
        ScrollView scrollView = (ScrollView) fragmentView;
        scrollView.setFillViewport(true);
        linearLayout = new LinearLayout(context);
        linearLayout.setOrientation(LinearLayout.VERTICAL);
        scrollView.addView(linearLayout, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        actionBar.setTitle(LocaleController.getString("ChannelSettingsTitle", R.string.ChannelSettingsTitle));
        fragmentView.setTag(Theme.key_windowBackgroundGray);
        fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
        headerCell2 = new HeaderCell(context, 23);
        headerCell2.setHeight(46);
        headerCell2.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        headerCell2.setText(LocaleController.getString("ChannelTypeHeader", R.string.ChannelTypeHeader));
        linearLayout.addView(headerCell2);
        linearLayout2 = new LinearLayout(context);
        linearLayout2.setOrientation(LinearLayout.VERTICAL);
        linearLayout2.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        linearLayout.addView(linearLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        radioButtonCell1 = new RadioButtonCell(context);
        radioButtonCell1.setBackgroundDrawable(Theme.getSelectorDrawable(false));
        radioButtonCell1.setTextAndValue(LocaleController.getString("ChannelPublic", R.string.ChannelPublic), LocaleController.getString("ChannelPublicInfo", R.string.ChannelPublicInfo), false, !isPrivate);
        linearLayout2.addView(radioButtonCell1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        radioButtonCell1.setOnClickListener(v -> {
            if (!isPrivate) {
                return;
            }
            isPrivate = false;
            updatePrivatePublic();
        });
        radioButtonCell2 = new RadioButtonCell(context);
        radioButtonCell2.setBackgroundDrawable(Theme.getSelectorDrawable(false));
        radioButtonCell2.setTextAndValue(LocaleController.getString("ChannelPrivate", R.string.ChannelPrivate), LocaleController.getString("ChannelPrivateInfo", R.string.ChannelPrivateInfo), false, isPrivate);
        linearLayout2.addView(radioButtonCell2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        radioButtonCell2.setOnClickListener(v -> {
            if (isPrivate) {
                return;
            }
            isPrivate = true;
            updatePrivatePublic();
        });
        sectionCell = new ShadowSectionCell(context);
        linearLayout.addView(sectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        linkContainer = new LinearLayout(context);
        linkContainer.setOrientation(LinearLayout.VERTICAL);
        linkContainer.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        linearLayout.addView(linkContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        headerCell = new HeaderCell(context);
        linkContainer.addView(headerCell);
        publicContainer = new LinearLayout(context);
        publicContainer.setOrientation(LinearLayout.HORIZONTAL);
        linkContainer.addView(publicContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 17, 7, 17, 0));
        editText = new EditTextBoldCursor(context);
        editText.setText(MessagesController.getInstance(currentAccount).linkPrefix + "/");
        editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        editText.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
        editText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        editText.setMaxLines(1);
        editText.setLines(1);
        editText.setEnabled(false);
        editText.setBackgroundDrawable(null);
        editText.setPadding(0, 0, 0, 0);
        editText.setSingleLine(true);
        editText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
        editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
        publicContainer.addView(editText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 36));
        descriptionTextView = new EditTextBoldCursor(context);
        descriptionTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        descriptionTextView.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
        descriptionTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        descriptionTextView.setMaxLines(1);
        descriptionTextView.setLines(1);
        descriptionTextView.setBackgroundDrawable(null);
        descriptionTextView.setPadding(0, 0, 0, 0);
        descriptionTextView.setSingleLine(true);
        descriptionTextView.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
        descriptionTextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
        descriptionTextView.setHint(LocaleController.getString("ChannelUsernamePlaceholder", R.string.ChannelUsernamePlaceholder));
        descriptionTextView.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        descriptionTextView.setCursorSize(AndroidUtilities.dp(20));
        descriptionTextView.setCursorWidth(1.5f);
        publicContainer.addView(descriptionTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36));
        descriptionTextView.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                checkUserName(descriptionTextView.getText().toString());
            }

            @Override
            public void afterTextChanged(Editable editable) {
            }
        });
        privateContainer = new LinearLayout(context);
        privateContainer.setOrientation(LinearLayout.VERTICAL);
        linkContainer.addView(privateContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        permanentLinkView = new LinkActionView(context, this, null, chatId, true, ChatObject.isChannel(getMessagesController().getChat(chatId)));
        // permanentLinkView.showOptions(false);
        permanentLinkView.hideRevokeOption(true);
        permanentLinkView.setUsers(0, null);
        privateContainer.addView(permanentLinkView);
        checkTextView = new TextView(context);
        checkTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
        checkTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
        checkTextView.setVisibility(View.GONE);
        linkContainer.addView(checkTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT, 17, 3, 17, 7));
        typeInfoCell = new TextInfoPrivacyCell(context);
        typeInfoCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
        linearLayout.addView(typeInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        loadingAdminedCell = new LoadingCell(context);
        linearLayout.addView(loadingAdminedCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        adminnedChannelsLayout = new LinearLayout(context);
        adminnedChannelsLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        adminnedChannelsLayout.setOrientation(LinearLayout.VERTICAL);
        linearLayout.addView(adminnedChannelsLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        adminedInfoCell = new TextInfoPrivacyCell(context);
        adminedInfoCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
        linearLayout.addView(adminedInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        updatePrivatePublic();
    }
    return fragmentView;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) RadioButtonCell(org.telegram.ui.Cells.RadioButtonCell) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) ImageUpdater(org.telegram.ui.Components.ImageUpdater) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AndroidUtilities(org.telegram.messenger.AndroidUtilities) Animator(android.animation.Animator) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) RadialProgressView(org.telegram.ui.Components.RadialProgressView) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) View(android.view.View) Canvas(android.graphics.Canvas) RLottieImageView(org.telegram.ui.Components.RLottieImageView) ObjectAnimator(android.animation.ObjectAnimator) ImageLocation(org.telegram.messenger.ImageLocation) InputType(android.text.InputType) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) ViewGroup(android.view.ViewGroup) NotificationCenter(org.telegram.messenger.NotificationCenter) AdminedChannelCell(org.telegram.ui.Cells.AdminedChannelCell) RadioButtonCell(org.telegram.ui.Cells.RadioButtonCell) TextView(android.widget.TextView) Paint(android.graphics.Paint) InputFilter(android.text.InputFilter) TextBlockCell(org.telegram.ui.Cells.TextBlockCell) EditorInfo(android.view.inputmethod.EditorInfo) TextWatcher(android.text.TextWatcher) Context(android.content.Context) Theme(org.telegram.ui.ActionBar.Theme) Dialog(android.app.Dialog) Intent(android.content.Intent) LocaleController(org.telegram.messenger.LocaleController) HeaderCell(org.telegram.ui.Cells.HeaderCell) Editable(android.text.Editable) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ArrayList(java.util.ArrayList) LinkActionView(org.telegram.ui.Components.LinkActionView) TLRPC(org.telegram.tgnet.TLRPC) ActionBar(org.telegram.ui.ActionBar.ActionBar) EditTextEmoji(org.telegram.ui.Components.EditTextEmoji) AnimatorSet(android.animation.AnimatorSet) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) R(org.telegram.messenger.R) BackupImageView(org.telegram.ui.Components.BackupImageView) TextUtils(android.text.TextUtils) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) MessagesController(org.telegram.messenger.MessagesController) Gravity(android.view.Gravity) TypedValue(android.util.TypedValue) ScrollView(android.widget.ScrollView) Vibrator(android.os.Vibrator) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) LoadingCell(org.telegram.ui.Cells.LoadingCell) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) LinkActionView(org.telegram.ui.Components.LinkActionView) HeaderCell(org.telegram.ui.Cells.HeaderCell) RLottieImageView(org.telegram.ui.Components.RLottieImageView) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) LoadingCell(org.telegram.ui.Cells.LoadingCell) BackupImageView(org.telegram.ui.Components.BackupImageView) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) ActionBar(org.telegram.ui.ActionBar.ActionBar) InputFilter(android.text.InputFilter) RadialProgressView(org.telegram.ui.Components.RadialProgressView) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) Bundle(android.os.Bundle) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) Canvas(android.graphics.Canvas) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) Paint(android.graphics.Paint) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) ImageView(android.widget.ImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) View(android.view.View) RLottieImageView(org.telegram.ui.Components.RLottieImageView) TextView(android.widget.TextView) LinkActionView(org.telegram.ui.Components.LinkActionView) BackupImageView(org.telegram.ui.Components.BackupImageView) ScrollView(android.widget.ScrollView) Paint(android.graphics.Paint) ScrollView(android.widget.ScrollView) FrameLayout(android.widget.FrameLayout) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) Vibrator(android.os.Vibrator) EditTextEmoji(org.telegram.ui.Components.EditTextEmoji) LinearLayout(android.widget.LinearLayout)

Example 23 with EditTextBoldCursor

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

the class ThemeDescription method setColor.

public void setColor(int color, boolean useDefault, boolean save) {
    if (save) {
        Theme.setColor(currentKey, color, useDefault);
    }
    currentColor = color;
    if (alphaOverride > 0) {
        color = Color.argb(alphaOverride, Color.red(color), Color.green(color), Color.blue(color));
    }
    if (paintToUpdate != null) {
        for (int a = 0; a < paintToUpdate.length; a++) {
            if ((changeFlags & FLAG_LINKCOLOR) != 0 && paintToUpdate[a] instanceof TextPaint) {
                ((TextPaint) paintToUpdate[a]).linkColor = color;
            } else {
                paintToUpdate[a].setColor(color);
            }
        }
    }
    if (drawablesToUpdate != null) {
        for (int a = 0; a < drawablesToUpdate.length; a++) {
            if (drawablesToUpdate[a] == null) {
                continue;
            }
            if (drawablesToUpdate[a] instanceof BackDrawable) {
                ((BackDrawable) drawablesToUpdate[a]).setColor(color);
            } else if (drawablesToUpdate[a] instanceof ScamDrawable) {
                ((ScamDrawable) drawablesToUpdate[a]).setColor(color);
            } else if (drawablesToUpdate[a] instanceof RLottieDrawable) {
                if (lottieLayerName != null) {
                    ((RLottieDrawable) drawablesToUpdate[a]).setLayerColor(lottieLayerName + ".**", color);
                }
            } else if (drawablesToUpdate[a] instanceof CombinedDrawable) {
                if ((changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
                    ((CombinedDrawable) drawablesToUpdate[a]).getBackground().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                } else {
                    ((CombinedDrawable) drawablesToUpdate[a]).getIcon().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                }
            } else if (drawablesToUpdate[a] instanceof AvatarDrawable) {
                ((AvatarDrawable) drawablesToUpdate[a]).setColor(color);
            } else if (drawablesToUpdate[a] instanceof AnimatedArrowDrawable) {
                ((AnimatedArrowDrawable) drawablesToUpdate[a]).setColor(color);
            } else {
                drawablesToUpdate[a].setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
            }
        }
    }
    if (viewToInvalidate != null && listClasses == null && listClassesFieldName == null) {
        if ((changeFlags & FLAG_CHECKTAG) == 0 || checkTag(currentKey, viewToInvalidate)) {
            if ((changeFlags & FLAG_BACKGROUND) != 0) {
                Drawable background = viewToInvalidate.getBackground();
                if (background instanceof MessageBackgroundDrawable) {
                    ((MessageBackgroundDrawable) background).setColor(color);
                    ((MessageBackgroundDrawable) background).setCustomPaint(null);
                } else {
                    viewToInvalidate.setBackgroundColor(color);
                }
            }
            if ((changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
                if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
                    if (viewToInvalidate instanceof EditTextBoldCursor) {
                        ((EditTextBoldCursor) viewToInvalidate).setErrorLineColor(color);
                    }
                } else {
                    Drawable drawable = viewToInvalidate.getBackground();
                    if (drawable instanceof CombinedDrawable) {
                        if ((changeFlags & FLAG_DRAWABLESELECTEDSTATE) != 0) {
                            drawable = ((CombinedDrawable) drawable).getBackground();
                        } else {
                            drawable = ((CombinedDrawable) drawable).getIcon();
                        }
                    }
                    if (drawable != null) {
                        if (drawable instanceof StateListDrawable || Build.VERSION.SDK_INT >= 21 && drawable instanceof RippleDrawable) {
                            Theme.setSelectorDrawableColor(drawable, color, (changeFlags & FLAG_DRAWABLESELECTEDSTATE) != 0);
                        } else if (drawable instanceof ShapeDrawable) {
                            ((ShapeDrawable) drawable).getPaint().setColor(color);
                        } else {
                            drawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                        }
                    }
                }
            }
        }
    }
    if (viewToInvalidate instanceof ActionBar) {
        if ((changeFlags & FLAG_AB_ITEMSCOLOR) != 0) {
            ((ActionBar) viewToInvalidate).setItemsColor(color, false);
        }
        if ((changeFlags & FLAG_AB_TITLECOLOR) != 0) {
            ((ActionBar) viewToInvalidate).setTitleColor(color);
        }
        if ((changeFlags & FLAG_AB_SELECTORCOLOR) != 0) {
            ((ActionBar) viewToInvalidate).setItemsBackgroundColor(color, false);
        }
        if ((changeFlags & FLAG_AB_AM_SELECTORCOLOR) != 0) {
            ((ActionBar) viewToInvalidate).setItemsBackgroundColor(color, true);
        }
        if ((changeFlags & FLAG_AB_AM_ITEMSCOLOR) != 0) {
            ((ActionBar) viewToInvalidate).setItemsColor(color, true);
        }
        if ((changeFlags & FLAG_AB_SUBTITLECOLOR) != 0) {
            ((ActionBar) viewToInvalidate).setSubtitleColor(color);
        }
        if ((changeFlags & FLAG_AB_AM_BACKGROUND) != 0) {
            ((ActionBar) viewToInvalidate).setActionModeColor(color);
        }
        if ((changeFlags & FLAG_AB_AM_TOPBACKGROUND) != 0) {
            ((ActionBar) viewToInvalidate).setActionModeTopColor(color);
        }
        if ((changeFlags & FLAG_AB_SEARCHPLACEHOLDER) != 0) {
            ((ActionBar) viewToInvalidate).setSearchTextColor(color, true);
        }
        if ((changeFlags & FLAG_AB_SEARCH) != 0) {
            ((ActionBar) viewToInvalidate).setSearchTextColor(color, false);
        }
        if ((changeFlags & FLAG_AB_SUBMENUITEM) != 0) {
            ((ActionBar) viewToInvalidate).setPopupItemsColor(color, (changeFlags & FLAG_IMAGECOLOR) != 0, false);
        }
        if ((changeFlags & FLAG_AB_SUBMENUBACKGROUND) != 0) {
            ((ActionBar) viewToInvalidate).setPopupBackgroundColor(color, false);
        }
    }
    if (viewToInvalidate instanceof VideoTimelineView) {
        ((VideoTimelineView) viewToInvalidate).setColor(color);
    }
    if (viewToInvalidate instanceof EmptyTextProgressView) {
        if ((changeFlags & FLAG_TEXTCOLOR) != 0) {
            ((EmptyTextProgressView) viewToInvalidate).setTextColor(color);
        } else if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
            ((EmptyTextProgressView) viewToInvalidate).setProgressBarColor(color);
        }
    }
    if (viewToInvalidate instanceof RadialProgressView) {
        ((RadialProgressView) viewToInvalidate).setProgressColor(color);
    } else if (viewToInvalidate instanceof LineProgressView) {
        if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
            ((LineProgressView) viewToInvalidate).setProgressColor(color);
        } else {
            ((LineProgressView) viewToInvalidate).setBackColor(color);
        }
    } else if (viewToInvalidate instanceof ContextProgressView) {
        ((ContextProgressView) viewToInvalidate).updateColors();
    } else if (viewToInvalidate instanceof SeekBarView) {
        if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
            ((SeekBarView) viewToInvalidate).setOuterColor(color);
        }
    }
    if ((changeFlags & FLAG_TEXTCOLOR) != 0) {
        if ((changeFlags & FLAG_CHECKTAG) == 0 || checkTag(currentKey, viewToInvalidate)) {
            if (viewToInvalidate instanceof TextView) {
                ((TextView) viewToInvalidate).setTextColor(color);
            } else if (viewToInvalidate instanceof NumberTextView) {
                ((NumberTextView) viewToInvalidate).setTextColor(color);
            } else if (viewToInvalidate instanceof SimpleTextView) {
                ((SimpleTextView) viewToInvalidate).setTextColor(color);
            } else if (viewToInvalidate instanceof ChatBigEmptyView) {
                ((ChatBigEmptyView) viewToInvalidate).setTextColor(color);
            }
        }
    }
    if ((changeFlags & FLAG_CURSORCOLOR) != 0) {
        if (viewToInvalidate instanceof EditTextBoldCursor) {
            ((EditTextBoldCursor) viewToInvalidate).setCursorColor(color);
        }
    }
    if ((changeFlags & FLAG_HINTTEXTCOLOR) != 0) {
        if (viewToInvalidate instanceof EditTextBoldCursor) {
            if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
                ((EditTextBoldCursor) viewToInvalidate).setHeaderHintColor(color);
            } else {
                ((EditTextBoldCursor) viewToInvalidate).setHintColor(color);
            }
        } else if (viewToInvalidate instanceof EditText) {
            ((EditText) viewToInvalidate).setHintTextColor(color);
        }
    }
    if (viewToInvalidate != null && (changeFlags & FLAG_SERVICEBACKGROUND) != 0) {
    }
    if ((changeFlags & FLAG_IMAGECOLOR) != 0) {
        if ((changeFlags & FLAG_CHECKTAG) == 0 || checkTag(currentKey, viewToInvalidate)) {
            if (viewToInvalidate instanceof ImageView) {
                if ((changeFlags & FLAG_USEBACKGROUNDDRAWABLE) != 0) {
                    Drawable drawable = ((ImageView) viewToInvalidate).getDrawable();
                    if (drawable instanceof StateListDrawable || Build.VERSION.SDK_INT >= 21 && drawable instanceof RippleDrawable) {
                        Theme.setSelectorDrawableColor(drawable, color, (changeFlags & FLAG_DRAWABLESELECTEDSTATE) != 0);
                    }
                } else {
                    ((ImageView) viewToInvalidate).setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                }
            } else if (viewToInvalidate instanceof BackupImageView) {
            // ((BackupImageView) viewToInvalidate).setResourceImageColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
            } else if (viewToInvalidate instanceof SimpleTextView) {
                SimpleTextView textView = (SimpleTextView) viewToInvalidate;
                textView.setSideDrawablesColor(color);
            } else if (viewToInvalidate instanceof TextView) {
                Drawable[] drawables = ((TextView) viewToInvalidate).getCompoundDrawables();
                if (drawables != null) {
                    for (int a = 0; a < drawables.length; a++) {
                        if (drawables[a] != null) {
                            drawables[a].setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                        }
                    }
                }
            }
        }
    }
    if (viewToInvalidate instanceof ScrollView) {
        if ((changeFlags & FLAG_LISTGLOWCOLOR) != 0) {
            AndroidUtilities.setScrollViewEdgeEffectColor((ScrollView) viewToInvalidate, color);
        }
    }
    if (viewToInvalidate instanceof ViewPager) {
        if ((changeFlags & FLAG_LISTGLOWCOLOR) != 0) {
            AndroidUtilities.setViewPagerEdgeEffectColor((ViewPager) viewToInvalidate, color);
        }
    }
    if (viewToInvalidate instanceof RecyclerListView) {
        RecyclerListView recyclerListView = (RecyclerListView) viewToInvalidate;
        if ((changeFlags & FLAG_SELECTOR) != 0) {
            recyclerListView.setListSelectorColor(color);
        }
        if ((changeFlags & FLAG_FASTSCROLL) != 0) {
            recyclerListView.updateFastScrollColors();
        }
        if ((changeFlags & FLAG_LISTGLOWCOLOR) != 0) {
            recyclerListView.setGlowColor(color);
        }
        if ((changeFlags & FLAG_SECTIONS) != 0) {
            ArrayList<View> headers = recyclerListView.getHeaders();
            if (headers != null) {
                for (int a = 0; a < headers.size(); a++) {
                    processViewColor(headers.get(a), color);
                }
            }
            headers = recyclerListView.getHeadersCache();
            if (headers != null) {
                for (int a = 0; a < headers.size(); a++) {
                    processViewColor(headers.get(a), color);
                }
            }
            View header = recyclerListView.getPinnedHeader();
            if (header != null) {
                processViewColor(header, color);
            }
        }
    } else if (viewToInvalidate != null && (listClasses == null || listClasses.length == 0)) {
        if ((changeFlags & FLAG_SELECTOR) != 0) {
            viewToInvalidate.setBackgroundDrawable(Theme.getSelectorDrawable(false));
        } else if ((changeFlags & FLAG_SELECTORWHITE) != 0) {
            viewToInvalidate.setBackgroundDrawable(Theme.getSelectorDrawable(true));
        }
    }
    if (listClasses != null) {
        if (viewToInvalidate instanceof RecyclerListView) {
            RecyclerListView recyclerListView = (RecyclerListView) viewToInvalidate;
            recyclerListView.getRecycledViewPool().clear();
            int count = recyclerListView.getHiddenChildCount();
            for (int a = 0; a < count; a++) {
                processViewColor(recyclerListView.getHiddenChildAt(a), color);
            }
            count = recyclerListView.getCachedChildCount();
            for (int a = 0; a < count; a++) {
                processViewColor(recyclerListView.getCachedChildAt(a), color);
            }
            count = recyclerListView.getAttachedScrapChildCount();
            for (int a = 0; a < count; a++) {
                processViewColor(recyclerListView.getAttachedScrapChildAt(a), color);
            }
        }
        if (viewToInvalidate instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) viewToInvalidate;
            int count = viewGroup.getChildCount();
            for (int a = 0; a < count; a++) {
                processViewColor(viewGroup.getChildAt(a), color);
            }
        }
        processViewColor(viewToInvalidate, color);
    }
    if (delegate != null) {
        delegate.didSetColor();
    }
    if (viewToInvalidate != null) {
        viewToInvalidate.invalidate();
    }
}
Also used : ContextProgressView(org.telegram.ui.Components.ContextProgressView) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) StateListDrawable(android.graphics.drawable.StateListDrawable) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ScamDrawable(org.telegram.ui.Components.ScamDrawable) MessageBackgroundDrawable(org.telegram.ui.Components.MessageBackgroundDrawable) BackupImageView(org.telegram.ui.Components.BackupImageView) TextView(android.widget.TextView) NumberTextView(org.telegram.ui.Components.NumberTextView) NumberTextView(org.telegram.ui.Components.NumberTextView) ImageView(android.widget.ImageView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) BackupImageView(org.telegram.ui.Components.BackupImageView) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) VideoTimelineView(org.telegram.ui.Components.VideoTimelineView) EditText(android.widget.EditText) RadialProgressView(org.telegram.ui.Components.RadialProgressView) ChatBigEmptyView(org.telegram.ui.Components.ChatBigEmptyView) ViewGroup(android.view.ViewGroup) AnimatedArrowDrawable(org.telegram.ui.Components.AnimatedArrowDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) StateListDrawable(android.graphics.drawable.StateListDrawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) LetterDrawable(org.telegram.ui.Components.LetterDrawable) ScamDrawable(org.telegram.ui.Components.ScamDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) MessageBackgroundDrawable(org.telegram.ui.Components.MessageBackgroundDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) SeekBarView(org.telegram.ui.Components.SeekBarView) ViewPager(androidx.viewpager.widget.ViewPager) ImageView(android.widget.ImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) View(android.view.View) ContextProgressView(org.telegram.ui.Components.ContextProgressView) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) TextView(android.widget.TextView) VideoTimelineView(org.telegram.ui.Components.VideoTimelineView) ChatBigEmptyView(org.telegram.ui.Components.ChatBigEmptyView) SeekBarView(org.telegram.ui.Components.SeekBarView) BackupImageView(org.telegram.ui.Components.BackupImageView) LineProgressView(org.telegram.ui.Components.LineProgressView) NumberTextView(org.telegram.ui.Components.NumberTextView) ScrollView(android.widget.ScrollView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint) RippleDrawable(android.graphics.drawable.RippleDrawable) ScrollView(android.widget.ScrollView) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) ShapeDrawable(android.graphics.drawable.ShapeDrawable) LineProgressView(org.telegram.ui.Components.LineProgressView) AnimatedArrowDrawable(org.telegram.ui.Components.AnimatedArrowDrawable) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable)

Example 24 with EditTextBoldCursor

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

the class ActionBarMenuItem method setIsSearchField.

public ActionBarMenuItem setIsSearchField(boolean value, boolean wrapInScrollView) {
    if (parentMenu == null) {
        return this;
    }
    if (value && searchContainer == null) {
        searchContainer = new FrameLayout(getContext()) {

            private boolean ignoreRequestLayout;

            @Override
            public void setVisibility(int visibility) {
                super.setVisibility(visibility);
                if (clearButton != null) {
                    clearButton.setVisibility(visibility);
                }
                if (wrappedSearchFrameLayout != null) {
                    wrappedSearchFrameLayout.setVisibility(visibility);
                }
            }

            @Override
            public void setAlpha(float alpha) {
                super.setAlpha(alpha);
                if (clearButton != null && clearButton.getTag() != null) {
                    clearButton.setAlpha(alpha);
                    clearButton.setScaleX(alpha);
                    clearButton.setScaleY(alpha);
                }
            }

            @Override
            protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                if (!wrapInScrollView) {
                    measureChildWithMargins(clearButton, widthMeasureSpec, 0, heightMeasureSpec, 0);
                }
                int width;
                if (!LocaleController.isRTL) {
                    if (searchFieldCaption.getVisibility() == VISIBLE) {
                        measureChildWithMargins(searchFieldCaption, widthMeasureSpec, MeasureSpec.getSize(widthMeasureSpec) / 2, heightMeasureSpec, 0);
                        width = searchFieldCaption.getMeasuredWidth() + AndroidUtilities.dp(4);
                    } else {
                        width = 0;
                    }
                    int minWidth = MeasureSpec.getSize(widthMeasureSpec);
                    ignoreRequestLayout = true;
                    measureChildWithMargins(searchFilterLayout, widthMeasureSpec, width, heightMeasureSpec, 0);
                    int filterWidth = searchFilterLayout.getVisibility() == View.VISIBLE ? searchFilterLayout.getMeasuredWidth() : 0;
                    measureChildWithMargins(searchField, widthMeasureSpec, width + filterWidth, heightMeasureSpec, 0);
                    ignoreRequestLayout = false;
                    setMeasuredDimension(Math.max(filterWidth + searchField.getMeasuredWidth(), minWidth), MeasureSpec.getSize(heightMeasureSpec));
                } else {
                    if (searchFieldCaption.getVisibility() == VISIBLE) {
                        measureChildWithMargins(searchFieldCaption, widthMeasureSpec, MeasureSpec.getSize(widthMeasureSpec) / 2, heightMeasureSpec, 0);
                        width = searchFieldCaption.getMeasuredWidth() + AndroidUtilities.dp(4);
                    } else {
                        width = 0;
                    }
                    int minWidth = MeasureSpec.getSize(widthMeasureSpec);
                    ignoreRequestLayout = true;
                    measureChildWithMargins(searchFilterLayout, widthMeasureSpec, width, heightMeasureSpec, 0);
                    int filterWidth = searchFilterLayout.getVisibility() == View.VISIBLE ? searchFilterLayout.getMeasuredWidth() : 0;
                    measureChildWithMargins(searchField, MeasureSpec.makeMeasureSpec(minWidth - AndroidUtilities.dp(12), MeasureSpec.UNSPECIFIED), width + filterWidth, heightMeasureSpec, 0);
                    ignoreRequestLayout = false;
                    setMeasuredDimension(Math.max(filterWidth + searchField.getMeasuredWidth(), minWidth), MeasureSpec.getSize(heightMeasureSpec));
                }
            }

            @Override
            public void requestLayout() {
                if (ignoreRequestLayout) {
                    return;
                }
                super.requestLayout();
            }

            @Override
            protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
                super.onLayout(changed, left, top, right, bottom);
                int x;
                if (LocaleController.isRTL) {
                    x = 0;
                } else {
                    if (searchFieldCaption.getVisibility() == VISIBLE) {
                        x = searchFieldCaption.getMeasuredWidth() + AndroidUtilities.dp(4);
                    } else {
                        x = 0;
                    }
                }
                if (searchFilterLayout.getVisibility() == VISIBLE) {
                    x += searchFilterLayout.getMeasuredWidth();
                }
                searchField.layout(x, searchField.getTop(), x + searchField.getMeasuredWidth(), searchField.getBottom());
            }
        };
        searchContainer.setClipChildren(false);
        wrappedSearchFrameLayout = null;
        if (wrapInScrollView) {
            wrappedSearchFrameLayout = new FrameLayout(getContext());
            HorizontalScrollView horizontalScrollView = new HorizontalScrollView(getContext()) {

                boolean isDragging;

                @Override
                public boolean onInterceptTouchEvent(MotionEvent ev) {
                    checkDragg(ev);
                    return super.onInterceptTouchEvent(ev);
                }

                @Override
                public boolean onTouchEvent(MotionEvent ev) {
                    checkDragg(ev);
                    return super.onTouchEvent(ev);
                }

                private void checkDragg(MotionEvent ev) {
                    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
                        isDragging = true;
                    } else if (ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_CANCEL) {
                        isDragging = false;
                    }
                }

                @Override
                protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
                    if (!isDragging) {
                        return;
                    }
                    super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
                }
            };
            horizontalScrollView.addView(searchContainer, LayoutHelper.createScroll(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, 0));
            horizontalScrollView.setHorizontalScrollBarEnabled(false);
            horizontalScrollView.setClipChildren(false);
            wrappedSearchFrameLayout.addView(horizontalScrollView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, 0, 0, 0, 48, 0));
            parentMenu.addView(wrappedSearchFrameLayout, 0, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 0, 0, 0, 0));
        } else {
            parentMenu.addView(searchContainer, 0, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 6, 0, 0, 0));
        }
        searchContainer.setVisibility(GONE);
        searchFieldCaption = new TextView(getContext());
        searchFieldCaption.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        searchFieldCaption.setTextColor(getThemedColor(Theme.key_actionBarDefaultSearch));
        searchFieldCaption.setSingleLine(true);
        searchFieldCaption.setEllipsize(TextUtils.TruncateAt.END);
        searchFieldCaption.setVisibility(GONE);
        searchFieldCaption.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
        searchField = new EditTextBoldCursor(getContext()) {

            @Override
            protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                int minWidth = MeasureSpec.getSize(widthMeasureSpec);
                setMeasuredDimension(Math.max(minWidth, getMeasuredWidth()) + AndroidUtilities.dp(3), getMeasuredHeight());
            }

            @Override
            protected void onSelectionChanged(int selStart, int selEnd) {
                super.onSelectionChanged(selStart, selEnd);
            }

            @Override
            public boolean onKeyDown(int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_DEL && searchField.length() == 0 && ((searchFieldCaption.getVisibility() == VISIBLE && searchFieldCaption.length() > 0) || hasRemovableFilters())) {
                    if (hasRemovableFilters()) {
                        FiltersView.MediaFilterData filterToRemove = currentSearchFilters.get(currentSearchFilters.size() - 1);
                        if (listener != null) {
                            listener.onSearchFilterCleared(filterToRemove);
                        }
                        removeSearchFilter(filterToRemove);
                    } else {
                        clearButton.callOnClick();
                    }
                    return true;
                }
                return super.onKeyDown(keyCode, event);
            }

            @Override
            public boolean onTouchEvent(MotionEvent event) {
                boolean result = super.onTouchEvent(event);
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    // hack to fix android bug with not opening keyboard
                    if (!AndroidUtilities.showKeyboard(this)) {
                        clearFocus();
                        requestFocus();
                    }
                }
                return result;
            }
        };
        searchField.setScrollContainer(false);
        searchField.setCursorWidth(1.5f);
        searchField.setCursorColor(getThemedColor(Theme.key_actionBarDefaultSearch));
        searchField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        searchField.setHintTextColor(getThemedColor(Theme.key_actionBarDefaultSearchPlaceholder));
        searchField.setTextColor(getThemedColor(Theme.key_actionBarDefaultSearch));
        searchField.setSingleLine(true);
        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);
                if (listener != null) {
                    listener.onSearchPressed(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;
                }
                if (listener != null) {
                    listener.onTextChanged(searchField);
                }
                checkClearButton();
                if (!currentSearchFilters.isEmpty()) {
                    if (!TextUtils.isEmpty(searchField.getText()) && selectedFilterIndex >= 0) {
                        selectedFilterIndex = -1;
                        onFiltersChanged();
                    }
                }
            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });
        searchField.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME_ACTION_SEARCH);
        searchField.setTextIsSelectable(false);
        searchFilterLayout = new LinearLayout(getContext());
        searchFilterLayout.setOrientation(LinearLayout.HORIZONTAL);
        searchFilterLayout.setVisibility(View.VISIBLE);
        if (!LocaleController.isRTL) {
            searchContainer.addView(searchFieldCaption, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 36, Gravity.CENTER_VERTICAL | Gravity.LEFT, 0, 5.5f, 0, 0));
            searchContainer.addView(searchField, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 36, Gravity.CENTER_VERTICAL, 6, 0, 48, 0));
            searchContainer.addView(searchFilterLayout, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 32, Gravity.CENTER_VERTICAL, 0, 0, 48, 0));
        } else {
            searchContainer.addView(searchFilterLayout, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 32, Gravity.CENTER_VERTICAL, 0, 0, 48, 0));
            searchContainer.addView(searchField, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 36, Gravity.CENTER_VERTICAL, 0, 0, wrapInScrollView ? 0 : 48, 0));
            searchContainer.addView(searchFieldCaption, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 36, Gravity.CENTER_VERTICAL | Gravity.RIGHT, 0, 5.5f, 48, 0));
        }
        searchFilterLayout.setClipChildren(false);
        clearButton = new ImageView(getContext()) {

            @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(progressDrawable = new CloseProgressDrawable2());
        clearButton.setColorFilter(new PorterDuffColorFilter(parentMenu.parentActionBar.itemsColor, 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("");
            } else if (hasRemovableFilters()) {
                searchField.hideActionMode();
                for (int i = 0; i < currentSearchFilters.size(); i++) {
                    if (listener != null && currentSearchFilters.get(i).removable) {
                        listener.onSearchFilterCleared(currentSearchFilters.get(i));
                    }
                }
                clearSearchFilters();
            } else if (searchFieldCaption != null && searchFieldCaption.getVisibility() == VISIBLE) {
                searchFieldCaption.setVisibility(GONE);
                if (listener != null) {
                    listener.onCaptionCleared();
                }
            }
            searchField.requestFocus();
            AndroidUtilities.showKeyboard(searchField);
        });
        clearButton.setContentDescription(LocaleController.getString("ClearButton", R.string.ClearButton));
        if (wrapInScrollView) {
            wrappedSearchFrameLayout.addView(clearButton, LayoutHelper.createFrame(48, LayoutHelper.MATCH_PARENT, Gravity.CENTER_VERTICAL | Gravity.RIGHT));
        } else {
            searchContainer.addView(clearButton, LayoutHelper.createFrame(48, LayoutHelper.MATCH_PARENT, Gravity.CENTER_VERTICAL | Gravity.RIGHT));
        }
    }
    isSearchField = value;
    return this;
}
Also used : MenuItem(android.view.MenuItem) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) CloseProgressDrawable2(org.telegram.ui.Components.CloseProgressDrawable2) MotionEvent(android.view.MotionEvent) KeyEvent(android.view.KeyEvent) ActionMode(android.view.ActionMode) FrameLayout(android.widget.FrameLayout) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) Menu(android.view.Menu) ImageView(android.widget.ImageView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) BackupImageView(org.telegram.ui.Components.BackupImageView) HorizontalScrollView(android.widget.HorizontalScrollView) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) LinearLayout(android.widget.LinearLayout)

Example 25 with EditTextBoldCursor

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

the class ContactAddActivity method createView.

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

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (firstNameField.getText().length() != 0) {
                    TLRPC.User user = getMessagesController().getUser(user_id);
                    user.first_name = firstNameField.getText().toString();
                    user.last_name = lastNameField.getText().toString();
                    getContactsController().addContact(user, checkBoxCell != null && checkBoxCell.isChecked());
                    SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
                    preferences.edit().putInt("dialog_bar_vis3" + user_id, 3).commit();
                    getNotificationCenter().postNotificationName(NotificationCenter.updateInterfaces, MessagesController.UPDATE_MASK_NAME);
                    getNotificationCenter().postNotificationName(NotificationCenter.peerSettingsDidLoad, user_id);
                    finishFragment();
                    if (delegate != null) {
                        delegate.didAddToContacts();
                    }
                }
            }
        }
    });
    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItem(done_button, LocaleController.getString("Done", R.string.Done).toUpperCase());
    fragmentView = new ScrollView(context);
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    ((ScrollView) fragmentView).addView(linearLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT));
    linearLayout.setOnTouchListener((v, event) -> true);
    FrameLayout frameLayout = new FrameLayout(context);
    linearLayout.addView(frameLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 24, 24, 24, 0));
    avatarImage = new BackupImageView(context);
    avatarImage.setRoundRadius(AndroidUtilities.dp(30));
    frameLayout.addView(avatarImage, LayoutHelper.createFrame(60, 60, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP));
    nameTextView = new TextView(context);
    nameTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    nameTextView.setLines(1);
    nameTextView.setMaxLines(1);
    nameTextView.setSingleLine(true);
    nameTextView.setEllipsize(TextUtils.TruncateAt.END);
    nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
    nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    frameLayout.addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 80, 3, LocaleController.isRTL ? 80 : 0, 0));
    onlineTextView = new TextView(context);
    onlineTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText3));
    onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    onlineTextView.setLines(1);
    onlineTextView.setMaxLines(1);
    onlineTextView.setSingleLine(true);
    onlineTextView.setEllipsize(TextUtils.TruncateAt.END);
    onlineTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT));
    frameLayout.addView(onlineTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 80, 32, LocaleController.isRTL ? 80 : 0, 0));
    firstNameField = new EditTextBoldCursor(context);
    firstNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    firstNameField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
    firstNameField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    firstNameField.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
    firstNameField.setMaxLines(1);
    firstNameField.setLines(1);
    firstNameField.setSingleLine(true);
    firstNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    firstNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    firstNameField.setImeOptions(EditorInfo.IME_ACTION_NEXT);
    firstNameField.setHint(LocaleController.getString("FirstName", R.string.FirstName));
    firstNameField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    firstNameField.setCursorSize(AndroidUtilities.dp(20));
    firstNameField.setCursorWidth(1.5f);
    linearLayout.addView(firstNameField, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 24, 24, 24, 0));
    firstNameField.setOnEditorActionListener((textView, i, keyEvent) -> {
        if (i == EditorInfo.IME_ACTION_NEXT) {
            lastNameField.requestFocus();
            lastNameField.setSelection(lastNameField.length());
            return true;
        }
        return false;
    });
    firstNameField.setOnFocusChangeListener(new View.OnFocusChangeListener() {

        boolean focued;

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!paused && !hasFocus && focued) {
                FileLog.d("changed");
            }
            focued = hasFocus;
        }
    });
    lastNameField = new EditTextBoldCursor(context);
    lastNameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    lastNameField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
    lastNameField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    lastNameField.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
    lastNameField.setMaxLines(1);
    lastNameField.setLines(1);
    lastNameField.setSingleLine(true);
    lastNameField.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    lastNameField.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    lastNameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
    lastNameField.setHint(LocaleController.getString("LastName", R.string.LastName));
    lastNameField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    lastNameField.setCursorSize(AndroidUtilities.dp(20));
    lastNameField.setCursorWidth(1.5f);
    linearLayout.addView(lastNameField, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, 24, 16, 24, 0));
    lastNameField.setOnEditorActionListener((textView, i, keyEvent) -> {
        if (i == EditorInfo.IME_ACTION_DONE) {
            doneButton.performClick();
            return true;
        }
        return false;
    });
    TLRPC.User user = getMessagesController().getUser(user_id);
    if (user != null) {
        if (user.phone == null) {
            if (phone != null) {
                user.phone = PhoneFormat.stripExceptNumbers(phone);
            }
        }
        firstNameField.setText(user.first_name);
        firstNameField.setSelection(firstNameField.length());
        lastNameField.setText(user.last_name);
    }
    infoTextView = new TextView(context);
    infoTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText4));
    infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    infoTextView.setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
    if (addContact) {
        if (!needAddException || TextUtils.isEmpty(user.phone)) {
            linearLayout.addView(infoTextView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 24, 18, 24, 0));
        }
        if (needAddException) {
            checkBoxCell = new CheckBoxCell(getParentActivity(), 0);
            checkBoxCell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
            checkBoxCell.setText(LocaleController.formatString("SharePhoneNumberWith", R.string.SharePhoneNumberWith, UserObject.getFirstName(user)), "", true, false);
            checkBoxCell.setPadding(AndroidUtilities.dp(7), 0, AndroidUtilities.dp(7), 0);
            checkBoxCell.setOnClickListener(v -> checkBoxCell.setChecked(!checkBoxCell.isChecked(), true));
            linearLayout.addView(checkBoxCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 10, 0, 0));
        }
    }
    return fragmentView;
}
Also used : SharedPreferences(android.content.SharedPreferences) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) View(android.view.View) BackupImageView(org.telegram.ui.Components.BackupImageView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) TLRPC(org.telegram.tgnet.TLRPC) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) ScrollView(android.widget.ScrollView) BackupImageView(org.telegram.ui.Components.BackupImageView) FrameLayout(android.widget.FrameLayout) TextView(android.widget.TextView) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) ActionBar(org.telegram.ui.ActionBar.ActionBar) LinearLayout(android.widget.LinearLayout)

Aggregations

EditTextBoldCursor (org.telegram.ui.Components.EditTextBoldCursor)37 View (android.view.View)27 TextView (android.widget.TextView)26 ActionBar (org.telegram.ui.ActionBar.ActionBar)26 FrameLayout (android.widget.FrameLayout)25 LinearLayout (android.widget.LinearLayout)25 Editable (android.text.Editable)24 TextWatcher (android.text.TextWatcher)24 ViewGroup (android.view.ViewGroup)23 TLRPC (org.telegram.tgnet.TLRPC)23 ActionBarMenu (org.telegram.ui.ActionBar.ActionBarMenu)21 Paint (android.graphics.Paint)20 Canvas (android.graphics.Canvas)19 ImageView (android.widget.ImageView)19 SuppressLint (android.annotation.SuppressLint)18 ScrollView (android.widget.ScrollView)18 TextPaint (android.text.TextPaint)17 ArrayList (java.util.ArrayList)17 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)15 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)15