Search in sources :

Example 6 with RLottieImageView

use of org.telegram.ui.Components.RLottieImageView 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 7 with RLottieImageView

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

the class ThemeDescription method processViewColor.

private void processViewColor(View child, int color) {
    for (int b = 0; b < listClasses.length; b++) {
        if (listClasses[b].isInstance(child)) {
            child.invalidate();
            boolean passedCheck;
            if ((changeFlags & FLAG_CHECKTAG) == 0 || checkTag(currentKey, child)) {
                passedCheck = true;
                child.invalidate();
                if (listClassesFieldName == null && (changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
                    Drawable drawable = child.getBackground();
                    if (drawable != null) {
                        if ((changeFlags & FLAG_CELLBACKGROUNDCOLOR) != 0) {
                            if (drawable instanceof CombinedDrawable) {
                                Drawable back = ((CombinedDrawable) drawable).getBackground();
                                if (back instanceof ColorDrawable) {
                                    ((ColorDrawable) back).setColor(color);
                                }
                            }
                        } else {
                            if (drawable instanceof CombinedDrawable) {
                                drawable = ((CombinedDrawable) drawable).getIcon();
                            } else if (drawable instanceof StateListDrawable || Build.VERSION.SDK_INT >= 21 && drawable instanceof RippleDrawable) {
                                Theme.setSelectorDrawableColor(drawable, color, (changeFlags & FLAG_DRAWABLESELECTEDSTATE) != 0);
                            }
                            drawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                        }
                    }
                } else if ((changeFlags & FLAG_CELLBACKGROUNDCOLOR) != 0) {
                    child.setBackgroundColor(color);
                } else if ((changeFlags & FLAG_TEXTCOLOR) != 0) {
                    if (child instanceof TextView) {
                        ((TextView) child).setTextColor(color);
                    } else if (child instanceof AudioPlayerAlert.ClippingTextViewSwitcher) {
                        for (int i = 0; i < 2; i++) {
                            TextView textView = i == 0 ? ((AudioPlayerAlert.ClippingTextViewSwitcher) child).getTextView() : ((AudioPlayerAlert.ClippingTextViewSwitcher) child).getNextTextView();
                            if (textView != null) {
                                textView.setTextColor(color);
                            }
                        }
                    }
                } else if ((changeFlags & FLAG_SERVICEBACKGROUND) != 0) {
                } else if ((changeFlags & FLAG_SELECTOR) != 0) {
                    child.setBackgroundDrawable(Theme.getSelectorDrawable(false));
                } else if ((changeFlags & FLAG_SELECTORWHITE) != 0) {
                    child.setBackgroundDrawable(Theme.getSelectorDrawable(true));
                }
            } else {
                passedCheck = false;
            }
            if (listClassesFieldName != null) {
                String key = listClasses[b] + "_" + listClassesFieldName[b];
                if (notFoundCachedFields != null && notFoundCachedFields.containsKey(key)) {
                    continue;
                }
                try {
                    Field field = cachedFields.get(key);
                    if (field == null) {
                        field = listClasses[b].getDeclaredField(listClassesFieldName[b]);
                        if (field != null) {
                            field.setAccessible(true);
                            cachedFields.put(key, field);
                        }
                    }
                    if (field != null) {
                        Object object = field.get(child);
                        if (object != null) {
                            if (!passedCheck && object instanceof View && !checkTag(currentKey, (View) object)) {
                                continue;
                            }
                            if (object instanceof View) {
                                ((View) object).invalidate();
                            }
                            if (lottieLayerName != null && object instanceof RLottieImageView) {
                                ((RLottieImageView) object).setLayerColor(lottieLayerName + ".**", color);
                            }
                            if ((changeFlags & FLAG_USEBACKGROUNDDRAWABLE) != 0 && object instanceof View) {
                                object = ((View) object).getBackground();
                            }
                            if ((changeFlags & FLAG_BACKGROUND) != 0 && object instanceof View) {
                                View view = (View) object;
                                Drawable background = view.getBackground();
                                if (background instanceof MessageBackgroundDrawable) {
                                    ((MessageBackgroundDrawable) background).setColor(color);
                                    ((MessageBackgroundDrawable) background).setCustomPaint(null);
                                } else {
                                    view.setBackgroundColor(color);
                                }
                            } else if (object instanceof EditTextCaption) {
                                if ((changeFlags & FLAG_HINTTEXTCOLOR) != 0) {
                                    ((EditTextCaption) object).setHintColor(color);
                                    ((EditTextCaption) object).setHintTextColor(color);
                                } else if ((changeFlags & FLAG_CURSORCOLOR) != 0) {
                                    ((EditTextCaption) object).setCursorColor(color);
                                } else {
                                    ((EditTextCaption) object).setTextColor(color);
                                }
                            } else if (object instanceof SimpleTextView) {
                                if ((changeFlags & FLAG_LINKCOLOR) != 0) {
                                    ((SimpleTextView) object).setLinkTextColor(color);
                                } else {
                                    ((SimpleTextView) object).setTextColor(color);
                                }
                            } else if (object instanceof TextView) {
                                TextView textView = (TextView) object;
                                if ((changeFlags & FLAG_IMAGECOLOR) != 0) {
                                    Drawable[] drawables = textView.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));
                                            }
                                        }
                                    }
                                } else if ((changeFlags & FLAG_LINKCOLOR) != 0) {
                                    textView.getPaint().linkColor = color;
                                    textView.invalidate();
                                } else if ((changeFlags & FLAG_FASTSCROLL) != 0) {
                                    CharSequence text = textView.getText();
                                    if (text instanceof SpannedString) {
                                        TypefaceSpan[] spans = ((SpannedString) text).getSpans(0, text.length(), TypefaceSpan.class);
                                        if (spans != null && spans.length > 0) {
                                            for (int i = 0; i < spans.length; i++) {
                                                spans[i].setColor(color);
                                            }
                                        }
                                    }
                                } else {
                                    textView.setTextColor(color);
                                }
                            } else if (object instanceof ImageView) {
                                ImageView imageView = (ImageView) object;
                                Drawable drawable = imageView.getDrawable();
                                if (drawable instanceof CombinedDrawable) {
                                    if ((changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
                                        ((CombinedDrawable) drawable).getBackground().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                    } else {
                                        ((CombinedDrawable) drawable).getIcon().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                    }
                                } else {
                                    imageView.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                }
                            } else if (object instanceof BackupImageView) {
                                Drawable drawable = ((BackupImageView) object).getImageReceiver().getStaticThumb();
                                if (drawable instanceof CombinedDrawable) {
                                    if ((changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
                                        ((CombinedDrawable) drawable).getBackground().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                    } else {
                                        ((CombinedDrawable) drawable).getIcon().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                    }
                                } else if (drawable != null) {
                                    drawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                }
                            } else if (object instanceof Drawable) {
                                if (object instanceof LetterDrawable) {
                                    if ((changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
                                        ((LetterDrawable) object).setBackgroundColor(color);
                                    } else {
                                        ((LetterDrawable) object).setColor(color);
                                    }
                                } else if (object instanceof CombinedDrawable) {
                                    if ((changeFlags & FLAG_BACKGROUNDFILTER) != 0) {
                                        ((CombinedDrawable) object).getBackground().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                    } else {
                                        ((CombinedDrawable) object).getIcon().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                    }
                                } else if (object instanceof StateListDrawable || Build.VERSION.SDK_INT >= 21 && object instanceof RippleDrawable) {
                                    Theme.setSelectorDrawableColor((Drawable) object, color, (changeFlags & FLAG_DRAWABLESELECTEDSTATE) != 0);
                                } else if (object instanceof GradientDrawable) {
                                    ((GradientDrawable) object).setColor(color);
                                } else {
                                    ((Drawable) object).setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
                                }
                            } else if (object instanceof CheckBox) {
                                if ((changeFlags & FLAG_CHECKBOX) != 0) {
                                    ((CheckBox) object).setBackgroundColor(color);
                                } else if ((changeFlags & FLAG_CHECKBOXCHECK) != 0) {
                                    ((CheckBox) object).setCheckColor(color);
                                }
                            } else if (object instanceof GroupCreateCheckBox) {
                                ((GroupCreateCheckBox) object).updateColors();
                            } else if (object instanceof Integer) {
                                field.set(child, color);
                            } else if (object instanceof RadioButton) {
                                if ((changeFlags & FLAG_CHECKBOX) != 0) {
                                    ((RadioButton) object).setBackgroundColor(color);
                                    ((RadioButton) object).invalidate();
                                } else if ((changeFlags & FLAG_CHECKBOXCHECK) != 0) {
                                    ((RadioButton) object).setCheckedColor(color);
                                    ((RadioButton) object).invalidate();
                                }
                            } else if (object instanceof TextPaint) {
                                if ((changeFlags & FLAG_LINKCOLOR) != 0) {
                                    ((TextPaint) object).linkColor = color;
                                } else {
                                    ((TextPaint) object).setColor(color);
                                }
                            } else if (object instanceof LineProgressView) {
                                if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
                                    ((LineProgressView) object).setProgressColor(color);
                                } else {
                                    ((LineProgressView) object).setBackColor(color);
                                }
                            } else if (object instanceof RadialProgressView) {
                                ((RadialProgressView) object).setProgressColor(color);
                            } else if (object instanceof Paint) {
                                ((Paint) object).setColor(color);
                                child.invalidate();
                            } else if (object instanceof SeekBarView) {
                                if ((changeFlags & FLAG_PROGRESSBAR) != 0) {
                                    ((SeekBarView) object).setOuterColor(color);
                                } else {
                                    ((SeekBarView) object).setInnerColor(color);
                                }
                            } else if (object instanceof AudioPlayerAlert.ClippingTextViewSwitcher) {
                                if ((changeFlags & FLAG_FASTSCROLL) != 0) {
                                    for (int k = 0; k < 2; k++) {
                                        TextView textView = k == 0 ? ((AudioPlayerAlert.ClippingTextViewSwitcher) object).getTextView() : ((AudioPlayerAlert.ClippingTextViewSwitcher) object).getNextTextView();
                                        if (textView != null) {
                                            CharSequence text = textView.getText();
                                            if (text instanceof SpannedString) {
                                                TypefaceSpan[] spans = ((SpannedString) text).getSpans(0, text.length(), TypefaceSpan.class);
                                                if (spans != null && spans.length > 0) {
                                                    for (int i = 0; i < spans.length; i++) {
                                                        spans[i].setColor(color);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } else if ((changeFlags & FLAG_TEXTCOLOR) != 0) {
                                    if ((changeFlags & FLAG_CHECKTAG) == 0 || checkTag(currentKey, (View) object)) {
                                        for (int i = 0; i < 2; i++) {
                                            TextView textView = i == 0 ? ((AudioPlayerAlert.ClippingTextViewSwitcher) object).getTextView() : ((AudioPlayerAlert.ClippingTextViewSwitcher) object).getNextTextView();
                                            if (textView != null) {
                                                textView.setTextColor(color);
                                                CharSequence text = textView.getText();
                                                if (text instanceof SpannedString) {
                                                    TypefaceSpan[] spans = ((SpannedString) text).getSpans(0, text.length(), TypefaceSpan.class);
                                                    if (spans != null && spans.length > 0) {
                                                        for (int spanIdx = 0; spanIdx < spans.length; spanIdx++) {
                                                            spans[spanIdx].setColor(color);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                } catch (Throwable e) {
                    FileLog.e(e);
                    notFoundCachedFields.put(key, true);
                }
            } else if (child instanceof GroupCreateSpan) {
                ((GroupCreateSpan) child).updateColors();
            }
        }
    }
}
Also used : SpannedString(android.text.SpannedString) RLottieImageView(org.telegram.ui.Components.RLottieImageView) AudioPlayerAlert(org.telegram.ui.Components.AudioPlayerAlert) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) SpannedString(android.text.SpannedString) StateListDrawable(android.graphics.drawable.StateListDrawable) MessageBackgroundDrawable(org.telegram.ui.Components.MessageBackgroundDrawable) Field(java.lang.reflect.Field) BackupImageView(org.telegram.ui.Components.BackupImageView) GroupCreateCheckBox(org.telegram.ui.Components.GroupCreateCheckBox) TextView(android.widget.TextView) NumberTextView(org.telegram.ui.Components.NumberTextView) ImageView(android.widget.ImageView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) BackupImageView(org.telegram.ui.Components.BackupImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) EditTextCaption(org.telegram.ui.Components.EditTextCaption) 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) RadioButton(org.telegram.ui.Components.RadioButton) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) 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) SeekBarView(org.telegram.ui.Components.SeekBarView) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) GradientDrawable(android.graphics.drawable.GradientDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) TextPaint(android.text.TextPaint) ColorDrawable(android.graphics.drawable.ColorDrawable) CheckBox(org.telegram.ui.Components.CheckBox) GroupCreateCheckBox(org.telegram.ui.Components.GroupCreateCheckBox) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) LetterDrawable(org.telegram.ui.Components.LetterDrawable) LineProgressView(org.telegram.ui.Components.LineProgressView) TypefaceSpan(org.telegram.ui.Components.TypefaceSpan) GroupCreateSpan(org.telegram.ui.Components.GroupCreateSpan)

Example 8 with RLottieImageView

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

the class AlertDialog method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    LinearLayout containerView = new LinearLayout(getContext()) {

        private boolean inLayout;

        @Override
        public boolean onTouchEvent(MotionEvent event) {
            if (progressViewStyle == 3) {
                showCancelAlert();
                return false;
            }
            return super.onTouchEvent(event);
        }

        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            if (progressViewStyle == 3) {
                showCancelAlert();
                return false;
            }
            return super.onInterceptTouchEvent(ev);
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            if (progressViewStyle == 3) {
                progressViewContainer.measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(86), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(86), MeasureSpec.EXACTLY));
                setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.getSize(heightMeasureSpec));
            } else {
                inLayout = true;
                int width = MeasureSpec.getSize(widthMeasureSpec);
                int height = MeasureSpec.getSize(heightMeasureSpec);
                int maxContentHeight;
                int availableHeight = maxContentHeight = height - getPaddingTop() - getPaddingBottom();
                int availableWidth = width - getPaddingLeft() - getPaddingRight();
                int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(availableWidth - AndroidUtilities.dp(48), MeasureSpec.EXACTLY);
                int childFullWidthMeasureSpec = MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.EXACTLY);
                LayoutParams layoutParams;
                if (buttonsLayout != null) {
                    int count = buttonsLayout.getChildCount();
                    for (int a = 0; a < count; a++) {
                        View child = buttonsLayout.getChildAt(a);
                        if (child instanceof TextView) {
                            TextView button = (TextView) child;
                            button.setMaxWidth(AndroidUtilities.dp((availableWidth - AndroidUtilities.dp(24)) / 2));
                        }
                    }
                    buttonsLayout.measure(childFullWidthMeasureSpec, heightMeasureSpec);
                    layoutParams = (LayoutParams) buttonsLayout.getLayoutParams();
                    availableHeight -= buttonsLayout.getMeasuredHeight() + layoutParams.bottomMargin + layoutParams.topMargin;
                }
                if (secondTitleTextView != null) {
                    secondTitleTextView.measure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(childWidthMeasureSpec), MeasureSpec.AT_MOST), heightMeasureSpec);
                }
                if (titleTextView != null) {
                    if (secondTitleTextView != null) {
                        titleTextView.measure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(childWidthMeasureSpec) - secondTitleTextView.getMeasuredWidth() - AndroidUtilities.dp(8), MeasureSpec.EXACTLY), heightMeasureSpec);
                    } else {
                        titleTextView.measure(childWidthMeasureSpec, heightMeasureSpec);
                    }
                }
                if (titleContainer != null) {
                    titleContainer.measure(childWidthMeasureSpec, heightMeasureSpec);
                    layoutParams = (LayoutParams) titleContainer.getLayoutParams();
                    availableHeight -= titleContainer.getMeasuredHeight() + layoutParams.bottomMargin + layoutParams.topMargin;
                }
                if (subtitleTextView != null) {
                    subtitleTextView.measure(childWidthMeasureSpec, heightMeasureSpec);
                    layoutParams = (LayoutParams) subtitleTextView.getLayoutParams();
                    availableHeight -= subtitleTextView.getMeasuredHeight() + layoutParams.bottomMargin + layoutParams.topMargin;
                }
                if (topImageView != null) {
                    topImageView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(topHeight), MeasureSpec.EXACTLY));
                    availableHeight -= topImageView.getMeasuredHeight() - AndroidUtilities.dp(8);
                }
                if (topView != null) {
                    int w = width - AndroidUtilities.dp(16);
                    int h;
                    if (aspectRatio == 0) {
                        float scale = w / 936.0f;
                        h = (int) (354 * scale);
                    } else {
                        h = (int) (w * aspectRatio);
                    }
                    topView.measure(MeasureSpec.makeMeasureSpec(w, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(h, MeasureSpec.EXACTLY));
                    topView.getLayoutParams().height = h;
                    availableHeight -= topView.getMeasuredHeight();
                }
                if (progressViewStyle == 0) {
                    layoutParams = (LayoutParams) contentScrollView.getLayoutParams();
                    if (customView != null) {
                        layoutParams.topMargin = titleTextView == null && messageTextView.getVisibility() == GONE && items == null ? AndroidUtilities.dp(16) : 0;
                        layoutParams.bottomMargin = buttonsLayout == null ? AndroidUtilities.dp(8) : 0;
                    } else if (items != null) {
                        layoutParams.topMargin = titleTextView == null && messageTextView.getVisibility() == GONE ? AndroidUtilities.dp(8) : 0;
                        layoutParams.bottomMargin = AndroidUtilities.dp(8);
                    } else if (messageTextView.getVisibility() == VISIBLE) {
                        layoutParams.topMargin = titleTextView == null ? AndroidUtilities.dp(19) : 0;
                        layoutParams.bottomMargin = AndroidUtilities.dp(20);
                    }
                    availableHeight -= layoutParams.bottomMargin + layoutParams.topMargin;
                    contentScrollView.measure(childFullWidthMeasureSpec, MeasureSpec.makeMeasureSpec(availableHeight, MeasureSpec.AT_MOST));
                    availableHeight -= contentScrollView.getMeasuredHeight();
                } else {
                    if (progressViewContainer != null) {
                        progressViewContainer.measure(childWidthMeasureSpec, MeasureSpec.makeMeasureSpec(availableHeight, MeasureSpec.AT_MOST));
                        layoutParams = (LayoutParams) progressViewContainer.getLayoutParams();
                        availableHeight -= progressViewContainer.getMeasuredHeight() + layoutParams.bottomMargin + layoutParams.topMargin;
                    } else if (messageTextView != null) {
                        messageTextView.measure(childWidthMeasureSpec, MeasureSpec.makeMeasureSpec(availableHeight, MeasureSpec.AT_MOST));
                        if (messageTextView.getVisibility() != GONE) {
                            layoutParams = (LayoutParams) messageTextView.getLayoutParams();
                            availableHeight -= messageTextView.getMeasuredHeight() + layoutParams.bottomMargin + layoutParams.topMargin;
                        }
                    }
                    if (lineProgressView != null) {
                        lineProgressView.measure(childWidthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(4), MeasureSpec.EXACTLY));
                        layoutParams = (LayoutParams) lineProgressView.getLayoutParams();
                        availableHeight -= lineProgressView.getMeasuredHeight() + layoutParams.bottomMargin + layoutParams.topMargin;
                        lineProgressViewPercent.measure(childWidthMeasureSpec, MeasureSpec.makeMeasureSpec(availableHeight, MeasureSpec.AT_MOST));
                        layoutParams = (LayoutParams) lineProgressViewPercent.getLayoutParams();
                        availableHeight -= lineProgressViewPercent.getMeasuredHeight() + layoutParams.bottomMargin + layoutParams.topMargin;
                    }
                }
                setMeasuredDimension(width, maxContentHeight - availableHeight + getPaddingTop() + getPaddingBottom());
                inLayout = false;
                if (lastScreenWidth != AndroidUtilities.displaySize.x) {
                    AndroidUtilities.runOnUIThread(() -> {
                        lastScreenWidth = AndroidUtilities.displaySize.x;
                        final int calculatedWidth = AndroidUtilities.displaySize.x - AndroidUtilities.dp(56);
                        int maxWidth;
                        if (AndroidUtilities.isTablet()) {
                            if (AndroidUtilities.isSmallTablet()) {
                                maxWidth = AndroidUtilities.dp(446);
                            } else {
                                maxWidth = AndroidUtilities.dp(496);
                            }
                        } else {
                            maxWidth = AndroidUtilities.dp(356);
                        }
                        Window window = getWindow();
                        WindowManager.LayoutParams params = new WindowManager.LayoutParams();
                        params.copyFrom(window.getAttributes());
                        params.width = Math.min(maxWidth, calculatedWidth) + backgroundPaddings.left + backgroundPaddings.right;
                        try {
                            window.setAttributes(params);
                        } catch (Throwable e) {
                            FileLog.e(e);
                        }
                    });
                }
            }
        }

        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b) {
            super.onLayout(changed, l, t, r, b);
            if (progressViewStyle == 3) {
                int x = (r - l - progressViewContainer.getMeasuredWidth()) / 2;
                int y = (b - t - progressViewContainer.getMeasuredHeight()) / 2;
                progressViewContainer.layout(x, y, x + progressViewContainer.getMeasuredWidth(), y + progressViewContainer.getMeasuredHeight());
            } else if (contentScrollView != null) {
                if (onScrollChangedListener == null) {
                    onScrollChangedListener = () -> {
                        runShadowAnimation(0, titleTextView != null && contentScrollView.getScrollY() > scrollContainer.getTop());
                        runShadowAnimation(1, buttonsLayout != null && contentScrollView.getScrollY() + contentScrollView.getHeight() < scrollContainer.getBottom());
                        contentScrollView.invalidate();
                    };
                    contentScrollView.getViewTreeObserver().addOnScrollChangedListener(onScrollChangedListener);
                }
                onScrollChangedListener.onScrollChanged();
            }
        }

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

        @Override
        public boolean hasOverlappingRendering() {
            return false;
        }

        @Override
        protected void dispatchDraw(Canvas canvas) {
            if (drawBackground) {
                shadowDrawable.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
                if (topView != null && notDrawBackgroundOnTopView) {
                    int clipTop = topView.getBottom();
                    canvas.save();
                    canvas.clipRect(0, clipTop, getMeasuredWidth(), getMeasuredHeight());
                    shadowDrawable.draw(canvas);
                    canvas.restore();
                } else {
                    shadowDrawable.draw(canvas);
                }
            }
            super.dispatchDraw(canvas);
        }
    };
    containerView.setOrientation(LinearLayout.VERTICAL);
    if (progressViewStyle == 3) {
        containerView.setBackgroundDrawable(null);
        containerView.setPadding(0, 0, 0, 0);
        drawBackground = false;
    } else {
        if (notDrawBackgroundOnTopView) {
            Rect rect = new Rect();
            shadowDrawable.getPadding(rect);
            containerView.setPadding(rect.left, rect.top, rect.right, rect.bottom);
            drawBackground = true;
        } else {
            containerView.setBackgroundDrawable(null);
            containerView.setPadding(0, 0, 0, 0);
            containerView.setBackgroundDrawable(shadowDrawable);
            drawBackground = false;
        }
    }
    containerView.setFitsSystemWindows(Build.VERSION.SDK_INT >= 21);
    setContentView(containerView);
    final boolean hasButtons = positiveButtonText != null || negativeButtonText != null || neutralButtonText != null;
    if (topResId != 0 || topAnimationId != 0 || topDrawable != null) {
        topImageView = new RLottieImageView(getContext());
        if (topDrawable != null) {
            topImageView.setImageDrawable(topDrawable);
        } else if (topResId != 0) {
            topImageView.setImageResource(topResId);
        } else {
            topImageView.setAutoRepeat(topAnimationAutoRepeat);
            topImageView.setAnimation(topAnimationId, topAnimationSize, topAnimationSize);
            topImageView.playAnimation();
        }
        topImageView.setScaleType(ImageView.ScaleType.CENTER);
        topImageView.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.popup_fixed_top));
        topImageView.getBackground().setColorFilter(new PorterDuffColorFilter(topBackgroundColor, PorterDuff.Mode.MULTIPLY));
        topImageView.setPadding(0, 0, 0, 0);
        containerView.addView(topImageView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, topHeight, Gravity.LEFT | Gravity.TOP, -8, -8, 0, 0));
    } else if (topView != null) {
        topView.setPadding(0, 0, 0, 0);
        containerView.addView(topView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, topHeight, Gravity.LEFT | Gravity.TOP, 0, 0, 0, 0));
    }
    if (title != null) {
        titleContainer = new FrameLayout(getContext());
        containerView.addView(titleContainer, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, 24, 0, 24, 0));
        titleTextView = new TextView(getContext());
        titleTextView.setText(title);
        titleTextView.setTextColor(getThemedColor(Theme.key_dialogTextBlack));
        titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
        titleTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
        titleTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
        titleContainer.addView(titleTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 0, 19, 0, (subtitle != null ? 2 : (items != null ? 14 : 10))));
    }
    if (secondTitle != null && title != null) {
        secondTitleTextView = new TextView(getContext());
        secondTitleTextView.setText(secondTitle);
        secondTitleTextView.setTextColor(getThemedColor(Theme.key_dialogTextGray3));
        secondTitleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
        secondTitleTextView.setGravity((LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP);
        titleContainer.addView(secondTitleTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP, 0, 21, 0, 0));
    }
    if (subtitle != null) {
        subtitleTextView = new TextView(getContext());
        subtitleTextView.setText(subtitle);
        subtitleTextView.setTextColor(getThemedColor(Theme.key_dialogIcon));
        subtitleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
        subtitleTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
        containerView.addView(subtitleTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 0, 24, items != null ? 14 : 10));
    }
    if (progressViewStyle == 0) {
        shadow[0] = (BitmapDrawable) getContext().getResources().getDrawable(R.drawable.header_shadow).mutate();
        shadow[1] = (BitmapDrawable) getContext().getResources().getDrawable(R.drawable.header_shadow_reverse).mutate();
        shadow[0].setAlpha(0);
        shadow[1].setAlpha(0);
        shadow[0].setCallback(this);
        shadow[1].setCallback(this);
        contentScrollView = new ScrollView(getContext()) {

            @Override
            protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
                boolean result = super.drawChild(canvas, child, drawingTime);
                if (shadow[0].getPaint().getAlpha() != 0) {
                    shadow[0].setBounds(0, getScrollY(), getMeasuredWidth(), getScrollY() + AndroidUtilities.dp(3));
                    shadow[0].draw(canvas);
                }
                if (shadow[1].getPaint().getAlpha() != 0) {
                    shadow[1].setBounds(0, getScrollY() + getMeasuredHeight() - AndroidUtilities.dp(3), getMeasuredWidth(), getScrollY() + getMeasuredHeight());
                    shadow[1].draw(canvas);
                }
                return result;
            }
        };
        contentScrollView.setVerticalScrollBarEnabled(false);
        AndroidUtilities.setScrollViewEdgeEffectColor(contentScrollView, getThemedColor(Theme.key_dialogScrollGlow));
        containerView.addView(contentScrollView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 0, 0, 0));
        scrollContainer = new LinearLayout(getContext());
        scrollContainer.setOrientation(LinearLayout.VERTICAL);
        contentScrollView.addView(scrollContainer, new ScrollView.LayoutParams(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    }
    messageTextView = new TextView(getContext());
    messageTextView.setTextColor(getThemedColor(Theme.key_dialogTextBlack));
    messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    messageTextView.setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
    messageTextView.setLinkTextColor(getThemedColor(Theme.key_dialogTextLink));
    if (!messageTextViewClickable) {
        messageTextView.setClickable(false);
        messageTextView.setEnabled(false);
    }
    messageTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    if (progressViewStyle == 1) {
        progressViewContainer = new FrameLayout(getContext());
        containerView.addView(progressViewContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 44, Gravity.LEFT | Gravity.TOP, 23, title == null ? 24 : 0, 23, 24));
        RadialProgressView progressView = new RadialProgressView(getContext(), resourcesProvider);
        progressView.setProgressColor(getThemedColor(Theme.key_dialogProgressCircle));
        progressViewContainer.addView(progressView, LayoutHelper.createFrame(44, 44, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP));
        messageTextView.setLines(1);
        messageTextView.setEllipsize(TextUtils.TruncateAt.END);
        progressViewContainer.addView(messageTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL, (LocaleController.isRTL ? 0 : 62), 0, (LocaleController.isRTL ? 62 : 0), 0));
    } else if (progressViewStyle == 2) {
        containerView.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, title == null ? 19 : 0, 24, 20));
        lineProgressView = new LineProgressView(getContext());
        lineProgressView.setProgress(currentProgress / 100.0f, false);
        lineProgressView.setProgressColor(getThemedColor(Theme.key_dialogLineProgress));
        lineProgressView.setBackColor(getThemedColor(Theme.key_dialogLineProgressBackground));
        containerView.addView(lineProgressView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 4, Gravity.LEFT | Gravity.CENTER_VERTICAL, 24, 0, 24, 0));
        lineProgressViewPercent = new TextView(getContext());
        lineProgressViewPercent.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
        lineProgressViewPercent.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
        lineProgressViewPercent.setTextColor(getThemedColor(Theme.key_dialogTextGray2));
        lineProgressViewPercent.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
        containerView.addView(lineProgressViewPercent, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 23, 4, 23, 24));
        updateLineProgressTextView();
    } else if (progressViewStyle == 3) {
        setCanceledOnTouchOutside(false);
        setCancelable(false);
        progressViewContainer = new FrameLayout(getContext());
        progressViewContainer.setBackgroundDrawable(Theme.createRoundRectDrawable(AndroidUtilities.dp(18), getThemedColor(Theme.key_dialog_inlineProgressBackground)));
        containerView.addView(progressViewContainer, LayoutHelper.createLinear(86, 86, Gravity.CENTER));
        RadialProgressView progressView = new RadialProgressView(getContext(), resourcesProvider);
        progressView.setProgressColor(getThemedColor(Theme.key_dialog_inlineProgress));
        progressViewContainer.addView(progressView, LayoutHelper.createLinear(86, 86));
    } else {
        scrollContainer.addView(messageTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 24, 0, 24, customView != null || items != null ? customViewOffset : 0));
    }
    if (!TextUtils.isEmpty(message)) {
        messageTextView.setText(message);
        messageTextView.setVisibility(View.VISIBLE);
    } else {
        messageTextView.setVisibility(View.GONE);
    }
    if (items != null) {
        FrameLayout rowLayout = null;
        int lastRowLayoutNum = 0;
        for (int a = 0; a < items.length; a++) {
            if (items[a] == null) {
                continue;
            }
            AlertDialogCell cell = new AlertDialogCell(getContext(), resourcesProvider);
            cell.setTextAndIcon(items[a], itemIcons != null ? itemIcons[a] : 0);
            cell.setTag(a);
            itemViews.add(cell);
            scrollContainer.addView(cell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
            cell.setOnClickListener(v -> {
                if (onClickListener != null) {
                    onClickListener.onClick(AlertDialog.this, (Integer) v.getTag());
                }
                dismiss();
            });
        }
    }
    if (customView != null) {
        if (customView.getParent() != null) {
            ViewGroup viewGroup = (ViewGroup) customView.getParent();
            viewGroup.removeView(customView);
        }
        scrollContainer.addView(customView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, customViewHeight));
    }
    if (hasButtons) {
        if (!verticalButtons) {
            int buttonsWidth = 0;
            TextPaint paint = new TextPaint();
            paint.setTextSize(AndroidUtilities.dp(14));
            if (positiveButtonText != null) {
                buttonsWidth += paint.measureText(positiveButtonText, 0, positiveButtonText.length()) + AndroidUtilities.dp(10);
            }
            if (negativeButtonText != null) {
                buttonsWidth += paint.measureText(negativeButtonText, 0, negativeButtonText.length()) + AndroidUtilities.dp(10);
            }
            if (neutralButtonText != null) {
                buttonsWidth += paint.measureText(neutralButtonText, 0, neutralButtonText.length()) + AndroidUtilities.dp(10);
            }
            if (buttonsWidth > AndroidUtilities.dp(320)) {
                verticalButtons = true;
            }
        }
        if (verticalButtons) {
            LinearLayout linearLayout = new LinearLayout(getContext());
            linearLayout.setOrientation(LinearLayout.VERTICAL);
            buttonsLayout = linearLayout;
        } else {
            buttonsLayout = new FrameLayout(getContext()) {

                @Override
                protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
                    int count = getChildCount();
                    View positiveButton = null;
                    int width = right - left;
                    for (int a = 0; a < count; a++) {
                        View child = getChildAt(a);
                        Integer tag = (Integer) child.getTag();
                        if (tag != null) {
                            if (tag == Dialog.BUTTON_POSITIVE) {
                                positiveButton = child;
                                if (LocaleController.isRTL) {
                                    child.layout(getPaddingLeft(), getPaddingTop(), getPaddingLeft() + child.getMeasuredWidth(), getPaddingTop() + child.getMeasuredHeight());
                                } else {
                                    child.layout(width - getPaddingRight() - child.getMeasuredWidth(), getPaddingTop(), width - getPaddingRight(), getPaddingTop() + child.getMeasuredHeight());
                                }
                            } else if (tag == Dialog.BUTTON_NEGATIVE) {
                                if (LocaleController.isRTL) {
                                    int x = getPaddingLeft();
                                    if (positiveButton != null) {
                                        x += positiveButton.getMeasuredWidth() + AndroidUtilities.dp(8);
                                    }
                                    child.layout(x, getPaddingTop(), x + child.getMeasuredWidth(), getPaddingTop() + child.getMeasuredHeight());
                                } else {
                                    int x = width - getPaddingRight() - child.getMeasuredWidth();
                                    if (positiveButton != null) {
                                        x -= positiveButton.getMeasuredWidth() + AndroidUtilities.dp(8);
                                    }
                                    child.layout(x, getPaddingTop(), x + child.getMeasuredWidth(), getPaddingTop() + child.getMeasuredHeight());
                                }
                            } else if (tag == Dialog.BUTTON_NEUTRAL) {
                                if (LocaleController.isRTL) {
                                    child.layout(width - getPaddingRight() - child.getMeasuredWidth(), getPaddingTop(), width - getPaddingRight(), getPaddingTop() + child.getMeasuredHeight());
                                } else {
                                    child.layout(getPaddingLeft(), getPaddingTop(), getPaddingLeft() + child.getMeasuredWidth(), getPaddingTop() + child.getMeasuredHeight());
                                }
                            }
                        } else {
                            int w = child.getMeasuredWidth();
                            int h = child.getMeasuredHeight();
                            int l;
                            int t;
                            if (positiveButton != null) {
                                l = positiveButton.getLeft() + (positiveButton.getMeasuredWidth() - w) / 2;
                                t = positiveButton.getTop() + (positiveButton.getMeasuredHeight() - h) / 2;
                            } else {
                                l = t = 0;
                            }
                            child.layout(l, t, l + w, t + h);
                        }
                    }
                }

                @Override
                protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                    int totalWidth = 0;
                    int availableWidth = getMeasuredWidth() - getPaddingLeft() - getPaddingRight();
                    int count = getChildCount();
                    for (int a = 0; a < count; a++) {
                        View child = getChildAt(a);
                        if (child instanceof TextView && child.getTag() != null) {
                            totalWidth += child.getMeasuredWidth();
                        }
                    }
                    if (totalWidth > availableWidth) {
                        View negative = findViewWithTag(BUTTON_NEGATIVE);
                        View neuntral = findViewWithTag(BUTTON_NEUTRAL);
                        if (negative != null && neuntral != null) {
                            if (negative.getMeasuredWidth() < neuntral.getMeasuredWidth()) {
                                neuntral.measure(MeasureSpec.makeMeasureSpec(neuntral.getMeasuredWidth() - (totalWidth - availableWidth), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(neuntral.getMeasuredHeight(), MeasureSpec.EXACTLY));
                            } else {
                                negative.measure(MeasureSpec.makeMeasureSpec(negative.getMeasuredWidth() - (totalWidth - availableWidth), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(negative.getMeasuredHeight(), MeasureSpec.EXACTLY));
                            }
                        }
                    }
                }
            };
        }
        buttonsLayout.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(8), AndroidUtilities.dp(8), AndroidUtilities.dp(8));
        containerView.addView(buttonsLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 52));
        if (positiveButtonText != null) {
            TextView textView = new TextView(getContext()) {

                @Override
                public void setEnabled(boolean enabled) {
                    super.setEnabled(enabled);
                    setAlpha(enabled ? 1.0f : 0.5f);
                }

                @Override
                public void setTextColor(int color) {
                    super.setTextColor(color);
                    setBackgroundDrawable(Theme.getRoundRectSelectorDrawable(color));
                }
            };
            textView.setMinWidth(AndroidUtilities.dp(64));
            textView.setTag(Dialog.BUTTON_POSITIVE);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
            textView.setTextColor(getThemedColor(dialogButtonColorKey));
            textView.setGravity(Gravity.CENTER);
            textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
            // textView.setLines(1);
            // textView.setSingleLine(true); //TODO
            textView.setText(positiveButtonText.toString().toUpperCase());
            textView.setBackgroundDrawable(Theme.getRoundRectSelectorDrawable(getThemedColor(dialogButtonColorKey)));
            textView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
            if (verticalButtons) {
                buttonsLayout.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 36, LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT));
            } else {
                buttonsLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 36, Gravity.TOP | Gravity.RIGHT));
            }
            textView.setOnClickListener(v -> {
                if (positiveButtonListener != null) {
                    positiveButtonListener.onClick(AlertDialog.this, Dialog.BUTTON_POSITIVE);
                }
                if (dismissDialogByButtons) {
                    dismiss();
                }
            });
        }
        if (negativeButtonText != null) {
            TextView textView = new TextView(getContext()) {

                @Override
                public void setEnabled(boolean enabled) {
                    super.setEnabled(enabled);
                    setAlpha(enabled ? 1.0f : 0.5f);
                }

                @Override
                public void setTextColor(int color) {
                    super.setTextColor(color);
                    setBackgroundDrawable(Theme.getRoundRectSelectorDrawable(color));
                }
            };
            textView.setMinWidth(AndroidUtilities.dp(64));
            textView.setTag(Dialog.BUTTON_NEGATIVE);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
            textView.setTextColor(getThemedColor(dialogButtonColorKey));
            textView.setGravity(Gravity.CENTER);
            textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
            textView.setEllipsize(TextUtils.TruncateAt.END);
            textView.setSingleLine(true);
            textView.setText(negativeButtonText.toString().toUpperCase());
            textView.setBackgroundDrawable(Theme.getRoundRectSelectorDrawable(getThemedColor(dialogButtonColorKey)));
            textView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
            if (verticalButtons) {
                buttonsLayout.addView(textView, 0, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 36, LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT));
            } else {
                buttonsLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 36, Gravity.TOP | Gravity.RIGHT));
            }
            textView.setOnClickListener(v -> {
                if (negativeButtonListener != null) {
                    negativeButtonListener.onClick(AlertDialog.this, Dialog.BUTTON_NEGATIVE);
                }
                if (dismissDialogByButtons) {
                    cancel();
                }
            });
        }
        if (neutralButtonText != null) {
            TextView textView = new TextView(getContext()) {

                @Override
                public void setEnabled(boolean enabled) {
                    super.setEnabled(enabled);
                    setAlpha(enabled ? 1.0f : 0.5f);
                }

                @Override
                public void setTextColor(int color) {
                    super.setTextColor(color);
                    setBackgroundDrawable(Theme.getRoundRectSelectorDrawable(color));
                }
            };
            textView.setMinWidth(AndroidUtilities.dp(64));
            textView.setTag(Dialog.BUTTON_NEUTRAL);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
            textView.setTextColor(getThemedColor(dialogButtonColorKey));
            textView.setGravity(Gravity.CENTER);
            textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
            textView.setEllipsize(TextUtils.TruncateAt.END);
            textView.setSingleLine(true);
            textView.setText(neutralButtonText.toString().toUpperCase());
            textView.setBackgroundDrawable(Theme.getRoundRectSelectorDrawable(getThemedColor(dialogButtonColorKey)));
            textView.setPadding(AndroidUtilities.dp(10), 0, AndroidUtilities.dp(10), 0);
            if (verticalButtons) {
                buttonsLayout.addView(textView, 1, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 36, LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT));
            } else {
                buttonsLayout.addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 36, Gravity.TOP | Gravity.LEFT));
            }
            textView.setOnClickListener(v -> {
                if (neutralButtonListener != null) {
                    neutralButtonListener.onClick(AlertDialog.this, Dialog.BUTTON_NEGATIVE);
                }
                if (dismissDialogByButtons) {
                    dismiss();
                }
            });
        }
        if (verticalButtons) {
            for (int i = 1; i < buttonsLayout.getChildCount(); i++) {
                ((ViewGroup.MarginLayoutParams) buttonsLayout.getChildAt(i).getLayoutParams()).topMargin = AndroidUtilities.dp(6);
            }
        }
    }
    Window window = getWindow();
    WindowManager.LayoutParams params = new WindowManager.LayoutParams();
    params.copyFrom(window.getAttributes());
    if (progressViewStyle == 3) {
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
    } else {
        if (dimEnabled) {
            params.dimAmount = 0.6f;
            params.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND;
        } else {
            params.dimAmount = 0f;
            params.flags ^= WindowManager.LayoutParams.FLAG_DIM_BEHIND;
        }
        lastScreenWidth = AndroidUtilities.displaySize.x;
        final int calculatedWidth = AndroidUtilities.displaySize.x - AndroidUtilities.dp(48);
        int maxWidth;
        if (AndroidUtilities.isTablet()) {
            if (AndroidUtilities.isSmallTablet()) {
                maxWidth = AndroidUtilities.dp(446);
            } else {
                maxWidth = AndroidUtilities.dp(496);
            }
        } else {
            maxWidth = AndroidUtilities.dp(356);
        }
        params.width = Math.min(maxWidth, calculatedWidth) + backgroundPaddings.left + backgroundPaddings.right;
    }
    if (customView == null || !checkFocusable || !canTextInput(customView)) {
        params.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
    } else {
        params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE;
    }
    if (Build.VERSION.SDK_INT >= 28) {
        params.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT;
    }
    window.setAttributes(params);
}
Also used : RLottieImageView(org.telegram.ui.Components.RLottieImageView) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) WindowManager(android.view.WindowManager) TextView(android.widget.TextView) Window(android.view.Window) Rect(android.graphics.Rect) RadialProgressView(org.telegram.ui.Components.RadialProgressView) ViewGroup(android.view.ViewGroup) Canvas(android.graphics.Canvas) ImageView(android.widget.ImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) View(android.view.View) RLottieImageView(org.telegram.ui.Components.RLottieImageView) LineProgressView(org.telegram.ui.Components.LineProgressView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) TextPaint(android.text.TextPaint) MotionEvent(android.view.MotionEvent) TextPaint(android.text.TextPaint) AndroidUtilities(org.telegram.messenger.AndroidUtilities) ScrollView(android.widget.ScrollView) FrameLayout(android.widget.FrameLayout) LineProgressView(org.telegram.ui.Components.LineProgressView) LinearLayout(android.widget.LinearLayout)

Example 9 with RLottieImageView

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

the class ContactsActivity method createView.

@Override
public View createView(Context context) {
    searching = false;
    searchWas = false;
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    if (destroyAfterSelect) {
        if (returnAsResult) {
            actionBar.setTitle(LocaleController.getString("SelectContact", R.string.SelectContact));
        } else {
            if (createSecretChat) {
                actionBar.setTitle(LocaleController.getString("NewSecretChat", R.string.NewSecretChat));
            } else {
                actionBar.setTitle(LocaleController.getString("NewMessageTitle", R.string.NewMessageTitle));
            }
        }
    } else {
        actionBar.setTitle(LocaleController.getString("Contacts", R.string.Contacts));
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == sort_button) {
                SharedConfig.toggleSortContactsByName();
                sortByName = SharedConfig.sortContactsByName;
                listViewAdapter.setSortType(sortByName ? 1 : 2, false);
                sortItem.setIcon(sortByName ? R.drawable.contacts_sort_time : R.drawable.contacts_sort_name);
            }
        }
    });
    ActionBarMenu menu = actionBar.createMenu();
    ActionBarMenuItem item = menu.addItem(search_button, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {

        @Override
        public void onSearchExpand() {
            searching = true;
            if (floatingButtonContainer != null) {
                floatingButtonContainer.setVisibility(View.GONE);
            }
            if (sortItem != null) {
                sortItem.setVisibility(View.GONE);
            }
        }

        @Override
        public void onSearchCollapse() {
            searchListViewAdapter.searchDialogs(null);
            searching = false;
            searchWas = false;
            listView.setAdapter(listViewAdapter);
            listView.setSectionsType(1);
            listViewAdapter.notifyDataSetChanged();
            listView.setFastScrollVisible(true);
            listView.setVerticalScrollBarEnabled(false);
            // emptyView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
            if (floatingButtonContainer != null) {
                floatingButtonContainer.setVisibility(View.VISIBLE);
                floatingHidden = true;
                floatingButtonContainer.setTranslationY(AndroidUtilities.dp(100));
                hideFloatingButton(false);
            }
            if (sortItem != null) {
                sortItem.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public void onTextChanged(EditText editText) {
            if (searchListViewAdapter == null) {
                return;
            }
            String text = editText.getText().toString();
            if (text.length() != 0) {
                searchWas = true;
                if (listView != null) {
                    listView.setAdapter(searchListViewAdapter);
                    listView.setSectionsType(0);
                    searchListViewAdapter.notifyDataSetChanged();
                    listView.setFastScrollVisible(false);
                    listView.setVerticalScrollBarEnabled(true);
                }
                emptyView.showProgress(true, true);
                searchListViewAdapter.searchDialogs(text);
            } else {
                if (listView != null) {
                    listView.setAdapter(listViewAdapter);
                    listView.setSectionsType(1);
                }
            }
        }
    });
    item.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));
    item.setContentDescription(LocaleController.getString("Search", R.string.Search));
    if (!createSecretChat && !returnAsResult) {
        sortItem = menu.addItem(sort_button, sortByName ? R.drawable.contacts_sort_time : R.drawable.contacts_sort_name);
        sortItem.setContentDescription(LocaleController.getString("AccDescrContactSorting", R.string.AccDescrContactSorting));
    }
    searchListViewAdapter = new SearchAdapter(context, ignoreUsers, allowUsernameSearch, false, false, allowBots, allowSelf, true, 0) {

        @Override
        protected void onSearchProgressChanged() {
            if (!searchInProgress() && getItemCount() == 0) {
                emptyView.showProgress(false, true);
            }
            showItemsAnimated();
        }
    };
    int inviteViaLink;
    if (chatId != 0) {
        TLRPC.Chat chat = getMessagesController().getChat(chatId);
        inviteViaLink = ChatObject.canUserDoAdminAction(chat, ChatObject.ACTION_INVITE) ? 1 : 0;
    } else if (channelId != 0) {
        TLRPC.Chat chat = getMessagesController().getChat(channelId);
        inviteViaLink = ChatObject.canUserDoAdminAction(chat, ChatObject.ACTION_INVITE) && TextUtils.isEmpty(chat.username) ? 2 : 0;
    } else {
        inviteViaLink = 0;
    }
    try {
        hasGps = ApplicationLoader.applicationContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
    } catch (Throwable e) {
        hasGps = false;
    }
    listViewAdapter = new ContactsAdapter(context, onlyUsers ? 1 : 0, needPhonebook, ignoreUsers, inviteViaLink, hasGps) {

        @Override
        public void notifyDataSetChanged() {
            super.notifyDataSetChanged();
            if (listView != null && listView.getAdapter() == this) {
                int count = super.getItemCount();
                if (needPhonebook) {
                    // emptyView.setVisibility(count == 2 ? View.VISIBLE : View.GONE);
                    listView.setFastScrollVisible(count != 2);
                } else {
                    // emptyView.setVisibility(count == 0 ? View.VISIBLE : View.GONE);
                    listView.setFastScrollVisible(count != 0);
                }
            }
        }
    };
    listViewAdapter.setSortType(sortItem != null ? (sortByName ? 1 : 2) : 0, false);
    listViewAdapter.setDisableSections(disableSections);
    fragmentView = new FrameLayout(context) {

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);
            if (listView.getAdapter() == listViewAdapter) {
                if (emptyView.getVisibility() == VISIBLE) {
                    emptyView.setTranslationY(AndroidUtilities.dp(74));
                }
            } else {
                emptyView.setTranslationY(AndroidUtilities.dp(0));
            }
        }
    };
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    FlickerLoadingView flickerLoadingView = new FlickerLoadingView(context);
    flickerLoadingView.setViewType(FlickerLoadingView.USERS_TYPE);
    flickerLoadingView.showDate(false);
    emptyView = new StickerEmptyView(context, flickerLoadingView, StickerEmptyView.STICKER_TYPE_SEARCH);
    emptyView.addView(flickerLoadingView, 0);
    emptyView.setAnimateLayoutChange(true);
    emptyView.showProgress(true, false);
    emptyView.title.setText(LocaleController.getString("NoResult", R.string.NoResult));
    emptyView.subtitle.setText(LocaleController.getString("SearchEmptyViewFilteredSubtitle2", R.string.SearchEmptyViewFilteredSubtitle2));
    frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView = new RecyclerListView(context) {

        @Override
        public void setPadding(int left, int top, int right, int bottom) {
            super.setPadding(left, top, right, bottom);
            if (emptyView != null) {
                emptyView.setPadding(left, top, right, bottom);
            }
        }
    };
    listView.setSectionsType(1);
    listView.setVerticalScrollBarEnabled(false);
    listView.setFastScrollEnabled(RecyclerListView.FastScroll.LETTER_TYPE);
    listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    listView.setAdapter(listViewAdapter);
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setEmptyView(emptyView);
    listView.setAnimateEmptyView(true, 0);
    listView.setOnItemClickListener((view, position) -> {
        if (listView.getAdapter() == searchListViewAdapter) {
            Object object = searchListViewAdapter.getItem(position);
            if (object instanceof TLRPC.User) {
                TLRPC.User user = (TLRPC.User) object;
                if (searchListViewAdapter.isGlobalSearch(position)) {
                    ArrayList<TLRPC.User> users = new ArrayList<>();
                    users.add(user);
                    getMessagesController().putUsers(users, false);
                    MessagesStorage.getInstance(currentAccount).putUsersAndChats(users, null, false, true);
                }
                if (returnAsResult) {
                    if (ignoreUsers != null && ignoreUsers.indexOfKey(user.id) >= 0) {
                        return;
                    }
                    didSelectResult(user, true, null);
                } else {
                    if (createSecretChat) {
                        if (user.id == UserConfig.getInstance(currentAccount).getClientUserId()) {
                            return;
                        }
                        creatingChat = true;
                        SecretChatHelper.getInstance(currentAccount).startSecretChat(getParentActivity(), user);
                    } else {
                        Bundle args = new Bundle();
                        args.putLong("user_id", user.id);
                        if (getMessagesController().checkCanOpenChat(args, ContactsActivity.this)) {
                            presentFragment(new ChatActivity(args), true);
                        }
                    }
                }
            } else if (object instanceof String) {
                String str = (String) object;
                if (!str.equals("section")) {
                    NewContactActivity activity = new NewContactActivity();
                    activity.setInitialPhoneNumber(str, true);
                    presentFragment(activity);
                }
            }
        } else {
            int section = listViewAdapter.getSectionForPosition(position);
            int row = listViewAdapter.getPositionInSectionForPosition(position);
            if (row < 0 || section < 0) {
                return;
            }
            if ((!onlyUsers || inviteViaLink != 0) && section == 0) {
                if (needPhonebook) {
                    if (row == 0) {
                        presentFragment(new InviteContactsActivity());
                    } else if (row == 1 && hasGps) {
                        if (Build.VERSION.SDK_INT >= 23) {
                            Activity activity = getParentActivity();
                            if (activity != null) {
                                if (activity.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                                    presentFragment(new ActionIntroActivity(ActionIntroActivity.ACTION_TYPE_NEARBY_LOCATION_ACCESS));
                                    return;
                                }
                            }
                        }
                        boolean enabled = true;
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
                            LocationManager lm = (LocationManager) ApplicationLoader.applicationContext.getSystemService(Context.LOCATION_SERVICE);
                            enabled = lm.isLocationEnabled();
                        } else if (Build.VERSION.SDK_INT >= 19) {
                            try {
                                int mode = Settings.Secure.getInt(ApplicationLoader.applicationContext.getContentResolver(), Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF);
                                enabled = (mode != Settings.Secure.LOCATION_MODE_OFF);
                            } catch (Throwable e) {
                                FileLog.e(e);
                            }
                        }
                        if (!enabled) {
                            presentFragment(new ActionIntroActivity(ActionIntroActivity.ACTION_TYPE_NEARBY_LOCATION_ENABLED));
                            return;
                        }
                        presentFragment(new PeopleNearbyActivity());
                    }
                } else if (inviteViaLink != 0) {
                    if (row == 0) {
                        presentFragment(new GroupInviteActivity(chatId != 0 ? chatId : channelId));
                    }
                } else {
                    if (row == 0) {
                        Bundle args = new Bundle();
                        presentFragment(new GroupCreateActivity(args), false);
                    } else if (row == 1) {
                        Bundle args = new Bundle();
                        args.putBoolean("onlyUsers", true);
                        args.putBoolean("destroyAfterSelect", true);
                        args.putBoolean("createSecretChat", true);
                        args.putBoolean("allowBots", false);
                        args.putBoolean("allowSelf", false);
                        presentFragment(new ContactsActivity(args), false);
                    } else if (row == 2) {
                        SharedPreferences preferences = MessagesController.getGlobalMainSettings();
                        if (!BuildVars.DEBUG_VERSION && preferences.getBoolean("channel_intro", false)) {
                            Bundle args = new Bundle();
                            args.putInt("step", 0);
                            presentFragment(new ChannelCreateActivity(args));
                        } else {
                            presentFragment(new ActionIntroActivity(ActionIntroActivity.ACTION_TYPE_CHANNEL_CREATE));
                            preferences.edit().putBoolean("channel_intro", true).commit();
                        }
                    }
                }
            } else {
                Object item1 = listViewAdapter.getItem(section, row);
                if (item1 instanceof TLRPC.User) {
                    TLRPC.User user = (TLRPC.User) item1;
                    if (returnAsResult) {
                        if (ignoreUsers != null && ignoreUsers.indexOfKey(user.id) >= 0) {
                            return;
                        }
                        didSelectResult(user, true, null);
                    } else {
                        if (createSecretChat) {
                            creatingChat = true;
                            SecretChatHelper.getInstance(currentAccount).startSecretChat(getParentActivity(), user);
                        } else {
                            Bundle args = new Bundle();
                            args.putLong("user_id", user.id);
                            if (getMessagesController().checkCanOpenChat(args, ContactsActivity.this)) {
                                presentFragment(new ChatActivity(args), true);
                            }
                        }
                    }
                } else if (item1 instanceof ContactsController.Contact) {
                    ContactsController.Contact contact = (ContactsController.Contact) item1;
                    String usePhone = null;
                    if (!contact.phones.isEmpty()) {
                        usePhone = contact.phones.get(0);
                    }
                    if (usePhone == null || getParentActivity() == null) {
                        return;
                    }
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setMessage(LocaleController.getString("InviteUser", R.string.InviteUser));
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    final String arg1 = usePhone;
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> {
                        try {
                            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", arg1, null));
                            intent.putExtra("sms_body", ContactsController.getInstance(currentAccount).getInviteText(1));
                            getParentActivity().startActivityForResult(intent, 500);
                        } catch (Exception e) {
                            FileLog.e(e);
                        }
                    });
                    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                    showDialog(builder.create());
                }
            }
        }
    });
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        private boolean scrollingManually;

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                if (searching && searchWas) {
                    AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
                }
                scrollingManually = true;
            } else {
                scrollingManually = false;
            }
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (floatingButtonContainer != null && floatingButtonContainer.getVisibility() != View.GONE) {
                int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
                final View topChild = recyclerView.getChildAt(0);
                int firstViewTop = 0;
                if (topChild != null) {
                    firstViewTop = topChild.getTop();
                }
                boolean goingDown;
                boolean changed = true;
                if (prevPosition == firstVisibleItem) {
                    final int topDelta = prevTop - firstViewTop;
                    goingDown = firstViewTop < prevTop;
                    changed = Math.abs(topDelta) > 1;
                } else {
                    goingDown = firstVisibleItem > prevPosition;
                }
                if (changed && scrollUpdated && (goingDown || scrollingManually)) {
                    hideFloatingButton(goingDown);
                }
                prevPosition = firstVisibleItem;
                prevTop = firstViewTop;
                scrollUpdated = true;
            }
        }
    });
    if (!createSecretChat && !returnAsResult) {
        floatingButtonContainer = new FrameLayout(context);
        frameLayout.addView(floatingButtonContainer, LayoutHelper.createFrame((Build.VERSION.SDK_INT >= 21 ? 56 : 60) + 20, (Build.VERSION.SDK_INT >= 21 ? 56 : 60) + 20, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 4 : 0, 0, LocaleController.isRTL ? 0 : 4, 0));
        floatingButtonContainer.setOnClickListener(v -> presentFragment(new NewContactActivity()));
        floatingButton = new RLottieImageView(context);
        floatingButton.setScaleType(ImageView.ScaleType.CENTER);
        Drawable drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_chats_actionBackground), Theme.getColor(Theme.key_chats_actionPressedBackground));
        if (Build.VERSION.SDK_INT < 21) {
            Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow).mutate();
            shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY));
            CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, drawable, 0, 0);
            combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56));
            drawable = combinedDrawable;
        }
        floatingButton.setBackgroundDrawable(drawable);
        floatingButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionIcon), PorterDuff.Mode.MULTIPLY));
        SharedPreferences preferences = MessagesController.getGlobalMainSettings();
        boolean configAnimationsEnabled = preferences.getBoolean("view_animations", true);
        floatingButton.setAnimation(configAnimationsEnabled ? R.raw.write_contacts_fab_icon : R.raw.write_contacts_fab_icon_reverse, 52, 52);
        floatingButtonContainer.setContentDescription(LocaleController.getString("CreateNewContact", R.string.CreateNewContact));
        if (Build.VERSION.SDK_INT >= 21) {
            StateListAnimator animator = new StateListAnimator();
            animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator.ofFloat(floatingButton, View.TRANSLATION_Z, AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
            animator.addState(new int[] {}, ObjectAnimator.ofFloat(floatingButton, View.TRANSLATION_Z, AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
            floatingButton.setStateListAnimator(animator);
            floatingButton.setOutlineProvider(new ViewOutlineProvider() {

                @SuppressLint("NewApi")
                @Override
                public void getOutline(View view, Outline outline) {
                    outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
                }
            });
        }
        floatingButtonContainer.addView(floatingButton, LayoutHelper.createFrame((Build.VERSION.SDK_INT >= 21 ? 56 : 60), (Build.VERSION.SDK_INT >= 21 ? 56 : 60), Gravity.LEFT | Gravity.TOP, 10, 6, 10, 0));
    }
    if (initialSearchString != null) {
        actionBar.openSearchField(initialSearchString, false);
        initialSearchString = null;
    }
    return fragmentView;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AndroidUtilities(org.telegram.messenger.AndroidUtilities) CubicBezierInterpolator(org.telegram.ui.Components.CubicBezierInterpolator) Animator(android.animation.Animator) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) Drawable(android.graphics.drawable.Drawable) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) Manifest(android.Manifest) ApplicationLoader(org.telegram.messenger.ApplicationLoader) StateListAnimator(android.animation.StateListAnimator) TextCell(org.telegram.ui.Cells.TextCell) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) ContactsAdapter(org.telegram.ui.Adapters.ContactsAdapter) TargetApi(android.annotation.TargetApi) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) Utilities(org.telegram.messenger.Utilities) RLottieImageView(org.telegram.ui.Components.RLottieImageView) ObjectAnimator(android.animation.ObjectAnimator) InputType(android.text.InputType) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PorterDuff(android.graphics.PorterDuff) ViewGroup(android.view.ViewGroup) NotificationCenter(org.telegram.messenger.NotificationCenter) Outline(android.graphics.Outline) UserConfig(org.telegram.messenger.UserConfig) SecretChatHelper(org.telegram.messenger.SecretChatHelper) LetterSectionCell(org.telegram.ui.Cells.LetterSectionCell) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) LocationManager(android.location.LocationManager) EditorInfo(android.view.inputmethod.EditorInfo) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) StickerEmptyView(org.telegram.ui.Components.StickerEmptyView) TextWatcher(android.text.TextWatcher) Context(android.content.Context) Theme(org.telegram.ui.ActionBar.Theme) ViewOutlineProvider(android.view.ViewOutlineProvider) BulletinFactory(org.telegram.ui.Components.BulletinFactory) Dialog(android.app.Dialog) Intent(android.content.Intent) SystemClock(android.os.SystemClock) LocaleController(org.telegram.messenger.LocaleController) AlertsCreator(org.telegram.ui.Components.AlertsCreator) Editable(android.text.Editable) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) TLRPC(org.telegram.tgnet.TLRPC) ActionBar(org.telegram.ui.ActionBar.ActionBar) AnimatorSet(android.animation.AnimatorSet) Settings(android.provider.Settings) SharedConfig(org.telegram.messenger.SharedConfig) BuildVars(org.telegram.messenger.BuildVars) Build(android.os.Build) ProfileSearchCell(org.telegram.ui.Cells.ProfileSearchCell) LongSparseArray(androidx.collection.LongSparseArray) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) UserCell(org.telegram.ui.Cells.UserCell) R(org.telegram.messenger.R) TextUtils(android.text.TextUtils) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) MessagesController(org.telegram.messenger.MessagesController) Gravity(android.view.Gravity) UserObject(org.telegram.messenger.UserObject) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ContactsController(org.telegram.messenger.ContactsController) MessagesStorage(org.telegram.messenger.MessagesStorage) GraySectionCell(org.telegram.ui.Cells.GraySectionCell) Configuration(android.content.res.Configuration) ViewTreeObserver(android.view.ViewTreeObserver) Activity(android.app.Activity) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) EditText(android.widget.EditText) SearchAdapter(org.telegram.ui.Adapters.SearchAdapter) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ValueAnimator(android.animation.ValueAnimator) ArrayList(java.util.ArrayList) Activity(android.app.Activity) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TLRPC(org.telegram.tgnet.TLRPC) ContactsAdapter(org.telegram.ui.Adapters.ContactsAdapter) ActionBar(org.telegram.ui.ActionBar.ActionBar) EditText(android.widget.EditText) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) Drawable(android.graphics.drawable.Drawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) StickerEmptyView(org.telegram.ui.Components.StickerEmptyView) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) UserObject(org.telegram.messenger.UserObject) ChatObject(org.telegram.messenger.ChatObject) ContactsController(org.telegram.messenger.ContactsController) RLottieImageView(org.telegram.ui.Components.RLottieImageView) StateListAnimator(android.animation.StateListAnimator) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) RecyclerListView(org.telegram.ui.Components.RecyclerListView) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) LocationManager(android.location.LocationManager) SearchAdapter(org.telegram.ui.Adapters.SearchAdapter) SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) Intent(android.content.Intent) Outline(android.graphics.Outline) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) StickerEmptyView(org.telegram.ui.Components.StickerEmptyView) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ViewOutlineProvider(android.view.ViewOutlineProvider) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) FrameLayout(android.widget.FrameLayout) SuppressLint(android.annotation.SuppressLint) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 10 with RLottieImageView

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

the class ContactsActivity method onCustomTransitionAnimation.

@Override
protected AnimatorSet onCustomTransitionAnimation(boolean isOpen, Runnable callback) {
    ValueAnimator valueAnimator = isOpen ? ValueAnimator.ofFloat(1f, 0) : ValueAnimator.ofFloat(0, 1f);
    ViewGroup parent = (ViewGroup) fragmentView.getParent();
    BaseFragment previousFragment = parentLayout.fragmentsStack.size() > 1 ? parentLayout.fragmentsStack.get(parentLayout.fragmentsStack.size() - 2) : null;
    DialogsActivity dialogsActivity = null;
    if (previousFragment instanceof DialogsActivity) {
        dialogsActivity = (DialogsActivity) previousFragment;
    }
    if (dialogsActivity == null) {
        return null;
    }
    RLottieImageView previousFab = dialogsActivity.getFloatingButton();
    View previousFabContainer = null;
    if (previousFab.getParent() != null) {
        previousFabContainer = (View) previousFab.getParent();
    }
    if (floatingButtonContainer == null || previousFabContainer == null || previousFab.getVisibility() != View.VISIBLE || Math.abs(previousFabContainer.getTranslationY()) > AndroidUtilities.dp(4) || Math.abs(floatingButtonContainer.getTranslationY()) > AndroidUtilities.dp(4)) {
        return null;
    }
    previousFab.setVisibility(View.GONE);
    if (isOpen) {
        parent.setAlpha(0f);
    }
    valueAnimator.addUpdateListener(valueAnimator1 -> {
        float v = (float) valueAnimator.getAnimatedValue();
        parent.setTranslationX(AndroidUtilities.dp(48) * v);
        parent.setAlpha(1f - v);
    });
    if (floatingButtonContainer != null) {
        ((ViewGroup) fragmentView).removeView(floatingButtonContainer);
        ((FrameLayout) parent.getParent()).addView(floatingButtonContainer);
    }
    valueAnimator.setDuration(150);
    valueAnimator.setInterpolator(new DecelerateInterpolator(1.5f));
    final int currentAccount = this.currentAccount;
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            if (floatingButtonContainer != null) {
                ViewGroup viewParent;
                if (floatingButtonContainer.getParent() instanceof ViewGroup) {
                    viewParent = (ViewGroup) floatingButtonContainer.getParent();
                    viewParent.removeView(floatingButtonContainer);
                }
                ((ViewGroup) fragmentView).addView(floatingButtonContainer);
                previousFab.setVisibility(View.VISIBLE);
                if (!isOpen) {
                    previousFab.setAnimation(R.raw.write_contacts_fab_icon_reverse, 52, 52);
                    previousFab.getAnimatedDrawable().setCurrentFrame(floatingButton.getAnimatedDrawable().getCurrentFrame());
                    previousFab.playAnimation();
                }
            }
            callback.run();
        }
    });
    animatorSet.playTogether(valueAnimator);
    AndroidUtilities.runOnUIThread(() -> {
        animationIndex = getNotificationCenter().setAnimationInProgress(animationIndex, null);
        animatorSet.start();
        if (isOpen) {
            floatingButton.setAnimation(R.raw.write_contacts_fab_icon, 52, 52);
            floatingButton.playAnimation();
        } else {
            floatingButton.setAnimation(R.raw.write_contacts_fab_icon_reverse, 52, 52);
            floatingButton.playAnimation();
        }
        if (bounceIconAnimator != null) {
            bounceIconAnimator.cancel();
        }
        bounceIconAnimator = new AnimatorSet();
        float totalDuration = floatingButton.getAnimatedDrawable().getDuration();
        long delay = 0;
        if (isOpen) {
            for (int i = 0; i < 6; i++) {
                AnimatorSet set = new AnimatorSet();
                if (i == 0) {
                    set.playTogether(ObjectAnimator.ofFloat(floatingButton, View.SCALE_X, 1f, 0.9f), ObjectAnimator.ofFloat(floatingButton, View.SCALE_Y, 1f, 0.9f), ObjectAnimator.ofFloat(previousFab, View.SCALE_X, 1f, 0.9f), ObjectAnimator.ofFloat(previousFab, View.SCALE_Y, 1f, 0.9f));
                    set.setDuration((long) (6f / 47f * totalDuration));
                    set.setInterpolator(CubicBezierInterpolator.EASE_OUT);
                } else if (i == 1) {
                    set.playTogether(ObjectAnimator.ofFloat(floatingButton, View.SCALE_X, 0.9f, 1.06f), ObjectAnimator.ofFloat(floatingButton, View.SCALE_Y, 0.9f, 1.06f), ObjectAnimator.ofFloat(previousFab, View.SCALE_X, 0.9f, 1.06f), ObjectAnimator.ofFloat(previousFab, View.SCALE_Y, 0.9f, 1.06f));
                    set.setDuration((long) (17f / 47f * totalDuration));
                    set.setInterpolator(CubicBezierInterpolator.EASE_BOTH);
                } else if (i == 2) {
                    set.playTogether(ObjectAnimator.ofFloat(floatingButton, View.SCALE_X, 1.06f, 0.9f), ObjectAnimator.ofFloat(floatingButton, View.SCALE_Y, 1.06f, 0.9f), ObjectAnimator.ofFloat(previousFab, View.SCALE_X, 1.06f, 0.9f), ObjectAnimator.ofFloat(previousFab, View.SCALE_Y, 1.06f, 0.9f));
                    set.setDuration((long) (10f / 47f * totalDuration));
                    set.setInterpolator(CubicBezierInterpolator.EASE_BOTH);
                } else if (i == 3) {
                    set.playTogether(ObjectAnimator.ofFloat(floatingButton, View.SCALE_X, 0.9f, 1.03f), ObjectAnimator.ofFloat(floatingButton, View.SCALE_Y, 0.9f, 1.03f), ObjectAnimator.ofFloat(previousFab, View.SCALE_X, 0.9f, 1.03f), ObjectAnimator.ofFloat(previousFab, View.SCALE_Y, 0.9f, 1.03f));
                    set.setDuration((long) (5f / 47f * totalDuration));
                    set.setInterpolator(CubicBezierInterpolator.EASE_BOTH);
                } else if (i == 4) {
                    set.playTogether(ObjectAnimator.ofFloat(floatingButton, View.SCALE_X, 1.03f, 0.98f), ObjectAnimator.ofFloat(floatingButton, View.SCALE_Y, 1.03f, 0.98f), ObjectAnimator.ofFloat(previousFab, View.SCALE_X, 1.03f, 0.98f), ObjectAnimator.ofFloat(previousFab, View.SCALE_Y, 1.03f, 0.98f));
                    set.setDuration((long) (5f / 47f * totalDuration));
                    set.setInterpolator(CubicBezierInterpolator.EASE_BOTH);
                } else {
                    set.playTogether(ObjectAnimator.ofFloat(floatingButton, View.SCALE_X, 0.98f, 1f), ObjectAnimator.ofFloat(floatingButton, View.SCALE_Y, 0.98f, 1f), ObjectAnimator.ofFloat(previousFab, View.SCALE_X, 0.98f, 1f), ObjectAnimator.ofFloat(previousFab, View.SCALE_Y, 0.98f, 1f));
                    set.setDuration((long) (4f / 47f * totalDuration));
                    set.setInterpolator(CubicBezierInterpolator.EASE_IN);
                }
                set.setStartDelay(delay);
                delay += set.getDuration();
                bounceIconAnimator.playTogether(set);
            }
        } else {
            for (int i = 0; i < 5; i++) {
                AnimatorSet set = new AnimatorSet();
                if (i == 0) {
                    set.playTogether(ObjectAnimator.ofFloat(floatingButton, View.SCALE_X, 1f, 0.9f), ObjectAnimator.ofFloat(floatingButton, View.SCALE_Y, 1f, 0.9f), ObjectAnimator.ofFloat(previousFab, View.SCALE_X, 1f, 0.9f), ObjectAnimator.ofFloat(previousFab, View.SCALE_Y, 1f, 0.9f));
                    set.setDuration((long) (7f / 36f * totalDuration));
                    set.setInterpolator(CubicBezierInterpolator.EASE_OUT);
                } else if (i == 1) {
                    set.playTogether(ObjectAnimator.ofFloat(floatingButton, View.SCALE_X, 0.9f, 1.06f), ObjectAnimator.ofFloat(floatingButton, View.SCALE_Y, 0.9f, 1.06f), ObjectAnimator.ofFloat(previousFab, View.SCALE_X, 0.9f, 1.06f), ObjectAnimator.ofFloat(previousFab, View.SCALE_Y, 0.9f, 1.06f));
                    set.setDuration((long) (8f / 36f * totalDuration));
                    set.setInterpolator(CubicBezierInterpolator.EASE_BOTH);
                } else if (i == 2) {
                    set.playTogether(ObjectAnimator.ofFloat(floatingButton, View.SCALE_X, 1.06f, 0.92f), ObjectAnimator.ofFloat(floatingButton, View.SCALE_Y, 1.06f, 0.92f), ObjectAnimator.ofFloat(previousFab, View.SCALE_X, 1.06f, 0.92f), ObjectAnimator.ofFloat(previousFab, View.SCALE_Y, 1.06f, 0.92f));
                    set.setDuration((long) (7f / 36f * totalDuration));
                    set.setInterpolator(CubicBezierInterpolator.EASE_BOTH);
                } else if (i == 3) {
                    set.playTogether(ObjectAnimator.ofFloat(floatingButton, View.SCALE_X, 0.92f, 1.02f), ObjectAnimator.ofFloat(floatingButton, View.SCALE_Y, 0.92f, 1.02f), ObjectAnimator.ofFloat(previousFab, View.SCALE_X, 0.92f, 1.02f), ObjectAnimator.ofFloat(previousFab, View.SCALE_Y, 0.92f, 1.02f));
                    set.setDuration((long) (9f / 36f * totalDuration));
                    set.setInterpolator(CubicBezierInterpolator.EASE_BOTH);
                } else {
                    set.playTogether(ObjectAnimator.ofFloat(floatingButton, View.SCALE_X, 1.02f, 1f), ObjectAnimator.ofFloat(floatingButton, View.SCALE_Y, 1.02f, 1f), ObjectAnimator.ofFloat(previousFab, View.SCALE_X, 1.02f, 1f), ObjectAnimator.ofFloat(previousFab, View.SCALE_Y, 1.02f, 1f));
                    set.setDuration((long) (5f / 47f * totalDuration));
                    set.setInterpolator(CubicBezierInterpolator.EASE_IN);
                }
                set.setStartDelay(delay);
                delay += set.getDuration();
                bounceIconAnimator.playTogether(set);
            }
        }
        bounceIconAnimator.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                floatingButton.setScaleX(1f);
                floatingButton.setScaleY(1f);
                previousFab.setScaleX(1f);
                previousFab.setScaleY(1f);
                bounceIconAnimator = null;
                getNotificationCenter().onAnimationFinish(animationIndex);
            }
        });
        bounceIconAnimator.start();
    }, 50);
    return animatorSet;
}
Also used : AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ViewGroup(android.view.ViewGroup) RLottieImageView(org.telegram.ui.Components.RLottieImageView) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) StickerEmptyView(org.telegram.ui.Components.StickerEmptyView) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) Animator(android.animation.Animator) StateListAnimator(android.animation.StateListAnimator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) FrameLayout(android.widget.FrameLayout)

Aggregations

RLottieImageView (org.telegram.ui.Components.RLottieImageView)14 View (android.view.View)12 FrameLayout (android.widget.FrameLayout)12 ImageView (android.widget.ImageView)12 TextView (android.widget.TextView)11 Canvas (android.graphics.Canvas)10 Paint (android.graphics.Paint)10 ViewGroup (android.view.ViewGroup)10 TLRPC (org.telegram.tgnet.TLRPC)10 RecyclerListView (org.telegram.ui.Components.RecyclerListView)10 Bundle (android.os.Bundle)9 LinearLayout (android.widget.LinearLayout)9 RecyclerView (androidx.recyclerview.widget.RecyclerView)9 ArrayList (java.util.ArrayList)9 ActionBar (org.telegram.ui.ActionBar.ActionBar)9 BaseFragment (org.telegram.ui.ActionBar.BaseFragment)9 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)8 AndroidUtilities (org.telegram.messenger.AndroidUtilities)8 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)8 Animator (android.animation.Animator)7