Search in sources :

Example 56 with ActionBarMenu

use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.

the class RestrictedLanguagesSelectActivity method createView.

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

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    ActionBarMenu menu = actionBar.createMenu();
    ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {

        @Override
        public void onSearchExpand() {
            searching = true;
        }

        @Override
        public void onSearchCollapse() {
            search(null);
            searching = false;
            searchWas = false;
            if (listView != null) {
                emptyView.setVisibility(View.GONE);
                listView.setAdapter(listAdapter);
            }
        }

        @Override
        public void onTextChanged(EditText editText) {
            String text = editText.getText().toString();
            search(text);
            if (text.length() != 0) {
                searchWas = true;
                if (listView != null) {
                    listView.setAdapter(searchListViewAdapter);
                }
            } else {
                searching = false;
                searchWas = false;
                if (listView != null) {
                    emptyView.setVisibility(View.GONE);
                    listView.setAdapter(listAdapter);
                }
            }
        }
    });
    item.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));
    listAdapter = new ListAdapter(context, false);
    searchListViewAdapter = new ListAdapter(context, true);
    fragmentView = new FrameLayout(context);
    fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    emptyView = new EmptyTextProgressView(context);
    emptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
    emptyView.showTextView();
    emptyView.setShowAtCenter(true);
    frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView = new RecyclerListView(context);
    listView.setEmptyView(emptyView);
    listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    listView.setVerticalScrollBarEnabled(false);
    listView.setAdapter(listAdapter);
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setOnItemClickListener((view, position) -> {
        if (getParentActivity() == null || parentLayout == null || !(view instanceof TextCheckbox2Cell)) {
            return;
        }
        boolean search = listView.getAdapter() == searchListViewAdapter;
        if (!search)
            position--;
        LocaleController.LocaleInfo localeInfo;
        if (search) {
            localeInfo = searchResult.get(position);
        } else {
            localeInfo = sortedLanguages.get(position);
        }
        if (localeInfo != null) {
            LocaleController.LocaleInfo currentLocaleInfo = LocaleController.getInstance().getCurrentLocaleInfo();
            String langCode = localeInfo.pluralLangCode;
            if (langCode != null && langCode.equals(currentLocaleInfo.pluralLangCode)) {
                AndroidUtilities.shakeView(((TextCheckbox2Cell) view).checkbox, 2, 0);
                return;
            }
            boolean value = selectedLanguages.contains(langCode);
            HashSet<String> newSelectedLanguages = new HashSet<String>(selectedLanguages);
            if (value)
                newSelectedLanguages.removeIf(s -> s != null && s.equals(langCode));
            else
                newSelectedLanguages.add(langCode);
            if (newSelectedLanguages.size() == 1 && newSelectedLanguages.contains(currentLocaleInfo.pluralLangCode))
                preferences.edit().remove("translate_button_restricted_languages").apply();
            else
                preferences.edit().putStringSet("translate_button_restricted_languages", newSelectedLanguages).apply();
        }
    });
    listView.setOnItemLongClickListener((view, position) -> {
        if (getParentActivity() == null || parentLayout == null || !(view instanceof TextCheckbox2Cell)) {
            return false;
        }
        boolean search = listView.getAdapter() == searchListViewAdapter;
        if (!search)
            position--;
        LocaleController.LocaleInfo localeInfo;
        if (search) {
            localeInfo = searchResult.get(position);
        } else {
            localeInfo = sortedLanguages.get(position);
        }
        if (localeInfo == null || localeInfo.pathToFile == null || localeInfo.isRemote() && localeInfo.serverIndex != Integer.MAX_VALUE) {
            return false;
        }
        final LocaleController.LocaleInfo finalLocaleInfo = localeInfo;
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        builder.setTitle(LocaleController.getString("DeleteLocalizationTitle", R.string.DeleteLocalizationTitle));
        builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("DeleteLocalizationText", R.string.DeleteLocalizationText, localeInfo.name)));
        builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialogInterface, i) -> {
            if (LocaleController.getInstance().deleteLanguage(finalLocaleInfo, currentAccount)) {
                fillLanguages();
                if (searchResult != null) {
                    searchResult.remove(finalLocaleInfo);
                }
                if (listAdapter != null) {
                    listAdapter.notifyDataSetChanged();
                }
                if (searchListViewAdapter != null) {
                    searchListViewAdapter.notifyDataSetChanged();
                }
            }
        });
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        AlertDialog alertDialog = builder.create();
        showDialog(alertDialog);
        TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
        if (button != null) {
            button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
        }
        return true;
    });
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
            }
        }
    });
    return fragmentView;
}
Also used : ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) Context(android.content.Context) LinearLayout(android.widget.LinearLayout) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) Arrays(java.util.Arrays) Theme(org.telegram.ui.ActionBar.Theme) FrameLayout(android.widget.FrameLayout) AndroidUtilities(org.telegram.messenger.AndroidUtilities) CubicBezierInterpolator(org.telegram.ui.Components.CubicBezierInterpolator) LocaleController(org.telegram.messenger.LocaleController) Timer(java.util.Timer) HeaderCell(org.telegram.ui.Cells.HeaderCell) TextCheckbox2Cell(org.telegram.ui.Cells.TextCheckbox2Cell) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) ActionBar(org.telegram.ui.ActionBar.ActionBar) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TimerTask(java.util.TimerTask) DialogInterface(android.content.DialogInterface) TextRadioCell(org.telegram.ui.Cells.TextRadioCell) Utilities(org.telegram.messenger.Utilities) TextSettingsCell(org.telegram.ui.Cells.TextSettingsCell) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) R(org.telegram.messenger.R) LanguageCell(org.telegram.ui.Cells.LanguageCell) Set(java.util.Set) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) ViewGroup(android.view.ViewGroup) MessagesController(org.telegram.messenger.MessagesController) NotificationCenter(org.telegram.messenger.NotificationCenter) TextView(android.widget.TextView) SharedPreferences(android.content.SharedPreferences) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Comparator(java.util.Comparator) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) Collections(java.util.Collections) EditText(android.widget.EditText) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ValueAnimator(android.animation.ValueAnimator) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) TextCheckbox2Cell(org.telegram.ui.Cells.TextCheckbox2Cell) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TextView(android.widget.TextView) ActionBar(org.telegram.ui.ActionBar.ActionBar) HashSet(java.util.HashSet) EditText(android.widget.EditText) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) LocaleController(org.telegram.messenger.LocaleController) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) FrameLayout(android.widget.FrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 57 with ActionBarMenu

use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.

the class PhotoAlbumPickerActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackgroundColor(Theme.getColor(Theme.key_dialogBackground));
    actionBar.setTitleColor(Theme.getColor(Theme.key_dialogTextBlack));
    actionBar.setItemsColor(Theme.getColor(Theme.key_dialogTextBlack), false);
    actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_dialogButtonSelector), false);
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == 1) {
                if (delegate != null) {
                    finishFragment(false);
                    delegate.startPhotoSelectActivity();
                }
            } else if (id == 2) {
                openPhotoPicker(null, 0);
            }
        }
    });
    ActionBarMenu menu = actionBar.createMenu();
    if (allowSearchImages) {
        menu.addItem(2, R.drawable.ic_ab_search).setContentDescription(LocaleController.getString("Search", R.string.Search));
    }
    ActionBarMenuItem menuItem = menu.addItem(0, R.drawable.ic_ab_other);
    menuItem.setContentDescription(LocaleController.getString("AccDescrMoreOptions", R.string.AccDescrMoreOptions));
    menuItem.addSubItem(1, R.drawable.msg_openin, LocaleController.getString("OpenInExternalApp", R.string.OpenInExternalApp));
    sizeNotifierFrameLayout = new SizeNotifierFrameLayout(context) {

        private int lastNotifyWidth;

        private boolean ignoreLayout;

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int widthSize = MeasureSpec.getSize(widthMeasureSpec);
            int heightSize = MeasureSpec.getSize(heightMeasureSpec);
            setMeasuredDimension(widthSize, heightSize);
            int keyboardSize = SharedConfig.smoothKeyboard ? 0 : measureKeyboardHeight();
            if (keyboardSize <= AndroidUtilities.dp(20)) {
                if (!AndroidUtilities.isInMultiwindow) {
                    heightSize -= commentTextView.getEmojiPadding();
                    heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
                }
            } else {
                ignoreLayout = true;
                commentTextView.hideEmojiView();
                ignoreLayout = false;
            }
            int childCount = getChildCount();
            for (int i = 0; i < childCount; i++) {
                View child = getChildAt(i);
                if (child == null || child.getVisibility() == GONE) {
                    continue;
                }
                if (commentTextView != null && commentTextView.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) {
            if (lastNotifyWidth != r - l) {
                lastNotifyWidth = r - l;
                if (sendPopupWindow != null && sendPopupWindow.isShowing()) {
                    sendPopupWindow.dismiss();
                }
            }
            final int count = getChildCount();
            int keyboardSize = SharedConfig.smoothKeyboard ? 0 : measureKeyboardHeight();
            int paddingBottom = keyboardSize <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow && !AndroidUtilities.isTablet() ? commentTextView.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 - l) - width - lp.rightMargin - getPaddingRight();
                        break;
                    case Gravity.LEFT:
                    default:
                        childLeft = lp.leftMargin + getPaddingLeft();
                }
                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 (commentTextView != null && commentTextView.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.setBackgroundColor(Theme.getColor(Theme.key_dialogBackground));
    fragmentView = sizeNotifierFrameLayout;
    actionBar.setTitle(LocaleController.getString("Gallery", R.string.Gallery));
    listView = new RecyclerListView(context);
    listView.setPadding(AndroidUtilities.dp(6), AndroidUtilities.dp(4), AndroidUtilities.dp(6), AndroidUtilities.dp(54));
    listView.setClipToPadding(false);
    listView.setHorizontalScrollBarEnabled(false);
    listView.setVerticalScrollBarEnabled(false);
    listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    listView.setDrawingCacheEnabled(false);
    sizeNotifierFrameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
    listView.setAdapter(listAdapter = new ListAdapter(context));
    listView.setGlowColor(Theme.getColor(Theme.key_dialogBackground));
    emptyView = new TextView(context);
    emptyView.setTextColor(0xff808080);
    emptyView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    emptyView.setGravity(Gravity.CENTER);
    emptyView.setVisibility(View.GONE);
    emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
    sizeNotifierFrameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, 48));
    emptyView.setOnTouchListener((v, event) -> true);
    progressView = new FrameLayout(context);
    progressView.setVisibility(View.GONE);
    sizeNotifierFrameLayout.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, 48));
    RadialProgressView progressBar = new RadialProgressView(context);
    progressBar.setProgressColor(0xff527da3);
    progressView.addView(progressBar, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
    shadow = new View(context);
    shadow.setBackgroundResource(R.drawable.header_shadow_reverse);
    shadow.setTranslationY(AndroidUtilities.dp(48));
    sizeNotifierFrameLayout.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48));
    frameLayout2 = new FrameLayout(context);
    frameLayout2.setBackgroundColor(Theme.getColor(Theme.key_dialogBackground));
    frameLayout2.setVisibility(View.INVISIBLE);
    frameLayout2.setTranslationY(AndroidUtilities.dp(48));
    sizeNotifierFrameLayout.addView(frameLayout2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM));
    frameLayout2.setOnTouchListener((v, event) -> true);
    if (commentTextView != null) {
        commentTextView.onDestroy();
    }
    commentTextView = new EditTextEmoji(context, sizeNotifierFrameLayout, null, EditTextEmoji.STYLE_DIALOG);
    InputFilter[] inputFilters = new InputFilter[1];
    inputFilters[0] = new InputFilter.LengthFilter(MessagesController.getInstance(UserConfig.selectedAccount).maxCaptionLength);
    commentTextView.setFilters(inputFilters);
    commentTextView.setHint(LocaleController.getString("AddCaption", R.string.AddCaption));
    EditTextBoldCursor editText = commentTextView.getEditText();
    editText.setMaxLines(1);
    editText.setSingleLine(true);
    frameLayout2.addView(commentTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 84, 0));
    if (caption != null) {
        commentTextView.setText(caption);
    }
    writeButtonContainer = new FrameLayout(context) {

        @Override
        public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
            super.onInitializeAccessibilityNodeInfo(info);
            info.setText(LocaleController.formatPluralString("AccDescrSendPhotos", selectedPhotos.size()));
            info.setClassName(Button.class.getName());
            info.setLongClickable(true);
            info.setClickable(true);
        }
    };
    writeButtonContainer.setFocusable(true);
    writeButtonContainer.setFocusableInTouchMode(true);
    writeButtonContainer.setVisibility(View.INVISIBLE);
    writeButtonContainer.setScaleX(0.2f);
    writeButtonContainer.setScaleY(0.2f);
    writeButtonContainer.setAlpha(0.0f);
    sizeNotifierFrameLayout.addView(writeButtonContainer, LayoutHelper.createFrame(60, 60, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, 12, 10));
    writeButton = new ImageView(context);
    writeButtonDrawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_dialogFloatingButton), Theme.getColor(Build.VERSION.SDK_INT >= 21 ? Theme.key_dialogFloatingButtonPressed : Theme.key_dialogFloatingButton));
    if (Build.VERSION.SDK_INT < 21) {
        Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow_profile).mutate();
        shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY));
        CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, writeButtonDrawable, 0, 0);
        combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56));
        writeButtonDrawable = combinedDrawable;
    }
    writeButton.setBackgroundDrawable(writeButtonDrawable);
    writeButton.setImageResource(R.drawable.attach_send);
    writeButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
    writeButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogFloatingIcon), PorterDuff.Mode.MULTIPLY));
    writeButton.setScaleType(ImageView.ScaleType.CENTER);
    if (Build.VERSION.SDK_INT >= 21) {
        writeButton.setOutlineProvider(new ViewOutlineProvider() {

            @SuppressLint("NewApi")
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
            }
        });
    }
    writeButtonContainer.addView(writeButton, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60, Gravity.LEFT | Gravity.TOP, Build.VERSION.SDK_INT >= 21 ? 2 : 0, 0, 0, 0));
    writeButton.setOnClickListener(v -> {
        if (chatActivity != null && chatActivity.isInScheduleMode()) {
            AlertsCreator.createScheduleDatePickerDialog(getParentActivity(), chatActivity.getDialogId(), (notify, scheduleDate) -> {
                sendSelectedPhotos(selectedPhotos, selectedPhotosOrder, notify, scheduleDate);
                finishFragment();
            });
        } else {
            sendSelectedPhotos(selectedPhotos, selectedPhotosOrder, true, 0);
            finishFragment();
        }
    });
    writeButton.setOnLongClickListener(view -> {
        if (chatActivity == null || maxSelectedPhotos == 1) {
            return false;
        }
        TLRPC.Chat chat = chatActivity.getCurrentChat();
        TLRPC.User user = chatActivity.getCurrentUser();
        if (sendPopupLayout == null) {
            sendPopupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getParentActivity());
            sendPopupLayout.setAnimationEnabled(false);
            sendPopupLayout.setOnTouchListener(new View.OnTouchListener() {

                private android.graphics.Rect popupRect = new android.graphics.Rect();

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                        if (sendPopupWindow != null && sendPopupWindow.isShowing()) {
                            v.getHitRect(popupRect);
                            if (!popupRect.contains((int) event.getX(), (int) event.getY())) {
                                sendPopupWindow.dismiss();
                            }
                        }
                    }
                    return false;
                }
            });
            sendPopupLayout.setDispatchKeyEventListener(keyEvent -> {
                if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0 && sendPopupWindow != null && sendPopupWindow.isShowing()) {
                    sendPopupWindow.dismiss();
                }
            });
            sendPopupLayout.setShownFromBotton(false);
            itemCells = new ActionBarMenuSubItem[2];
            for (int a = 0; a < 2; a++) {
                if (a == 0 && !chatActivity.canScheduleMessage() || a == 1 && UserObject.isUserSelf(user)) {
                    continue;
                }
                int num = a;
                itemCells[a] = new ActionBarMenuSubItem(getParentActivity(), a == 0, a == 1);
                if (num == 0) {
                    if (UserObject.isUserSelf(user)) {
                        itemCells[a].setTextAndIcon(LocaleController.getString("SetReminder", R.string.SetReminder), R.drawable.msg_schedule);
                    } else {
                        itemCells[a].setTextAndIcon(LocaleController.getString("ScheduleMessage", R.string.ScheduleMessage), R.drawable.msg_schedule);
                    }
                } else {
                    itemCells[a].setTextAndIcon(LocaleController.getString("SendWithoutSound", R.string.SendWithoutSound), R.drawable.input_notify_off);
                }
                itemCells[a].setMinimumWidth(AndroidUtilities.dp(196));
                sendPopupLayout.addView(itemCells[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
                itemCells[a].setOnClickListener(v -> {
                    if (sendPopupWindow != null && sendPopupWindow.isShowing()) {
                        sendPopupWindow.dismiss();
                    }
                    if (num == 0) {
                        AlertsCreator.createScheduleDatePickerDialog(getParentActivity(), chatActivity.getDialogId(), (notify, scheduleDate) -> {
                            sendSelectedPhotos(selectedPhotos, selectedPhotosOrder, notify, scheduleDate);
                            finishFragment();
                        });
                    } else {
                        sendSelectedPhotos(selectedPhotos, selectedPhotosOrder, true, 0);
                        finishFragment();
                    }
                });
            }
            sendPopupLayout.setupRadialSelectors(Theme.getColor(Theme.key_dialogButtonSelector));
            sendPopupWindow = new ActionBarPopupWindow(sendPopupLayout, LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT);
            sendPopupWindow.setAnimationEnabled(false);
            sendPopupWindow.setAnimationStyle(R.style.PopupContextAnimation2);
            sendPopupWindow.setOutsideTouchable(true);
            sendPopupWindow.setClippingEnabled(true);
            sendPopupWindow.setInputMethodMode(ActionBarPopupWindow.INPUT_METHOD_NOT_NEEDED);
            sendPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
            sendPopupWindow.getContentView().setFocusableInTouchMode(true);
        }
        sendPopupLayout.measure(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), View.MeasureSpec.AT_MOST));
        sendPopupWindow.setFocusable(true);
        int[] location = new int[2];
        view.getLocationInWindow(location);
        sendPopupWindow.showAtLocation(view, Gravity.LEFT | Gravity.TOP, location[0] + view.getMeasuredWidth() - sendPopupLayout.getMeasuredWidth() + AndroidUtilities.dp(8), location[1] - sendPopupLayout.getMeasuredHeight() - AndroidUtilities.dp(2));
        sendPopupWindow.dimBehind();
        view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
        return false;
    });
    textPaint.setTextSize(AndroidUtilities.dp(12));
    textPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    selectedCountView = new View(context) {

        @Override
        protected void onDraw(Canvas canvas) {
            String text = String.format("%d", Math.max(1, selectedPhotosOrder.size()));
            int textSize = (int) Math.ceil(textPaint.measureText(text));
            int size = Math.max(AndroidUtilities.dp(16) + textSize, AndroidUtilities.dp(24));
            int cx = getMeasuredWidth() / 2;
            int cy = getMeasuredHeight() / 2;
            textPaint.setColor(Theme.getColor(Theme.key_dialogRoundCheckBoxCheck));
            paint.setColor(Theme.getColor(Theme.key_dialogBackground));
            rect.set(cx - size / 2, 0, cx + size / 2, getMeasuredHeight());
            canvas.drawRoundRect(rect, AndroidUtilities.dp(12), AndroidUtilities.dp(12), paint);
            paint.setColor(Theme.getColor(Theme.key_dialogRoundCheckBox));
            rect.set(cx - size / 2 + AndroidUtilities.dp(2), AndroidUtilities.dp(2), cx + size / 2 - AndroidUtilities.dp(2), getMeasuredHeight() - AndroidUtilities.dp(2));
            canvas.drawRoundRect(rect, AndroidUtilities.dp(10), AndroidUtilities.dp(10), paint);
            canvas.drawText(text, cx - textSize / 2, AndroidUtilities.dp(16.2f), textPaint);
        }
    };
    selectedCountView.setAlpha(0.0f);
    selectedCountView.setScaleX(0.2f);
    selectedCountView.setScaleY(0.2f);
    sizeNotifierFrameLayout.addView(selectedCountView, LayoutHelper.createFrame(42, 24, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, -2, 9));
    if (selectPhotoType != SELECT_TYPE_ALL) {
        commentTextView.setVisibility(View.GONE);
    }
    if (loading && (albumsSorted == null || albumsSorted.isEmpty())) {
        progressView.setVisibility(View.VISIBLE);
        listView.setEmptyView(null);
    } else {
        progressView.setVisibility(View.GONE);
        listView.setEmptyView(emptyView);
    }
    return fragmentView;
}
Also used : PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TLRPC(org.telegram.tgnet.TLRPC) ActionBarPopupWindow(org.telegram.ui.ActionBar.ActionBarPopupWindow) ActionBarMenuSubItem(org.telegram.ui.ActionBar.ActionBarMenuSubItem) TextView(android.widget.TextView) ImageView(android.widget.ImageView) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) ActionBar(org.telegram.ui.ActionBar.ActionBar) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) InputFilter(android.text.InputFilter) RadialProgressView(org.telegram.ui.Components.RadialProgressView) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) Outline(android.graphics.Outline) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) ImageView(android.widget.ImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ViewOutlineProvider(android.view.ViewOutlineProvider) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) FrameLayout(android.widget.FrameLayout) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) SuppressLint(android.annotation.SuppressLint) EditTextEmoji(org.telegram.ui.Components.EditTextEmoji)

Example 58 with ActionBarMenu

use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.

the class PhotoCropActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackgroundColor(Theme.ACTION_BAR_MEDIA_PICKER_COLOR);
    actionBar.setItemsBackgroundColor(Theme.ACTION_BAR_PICKER_SELECTOR_COLOR, false);
    actionBar.setTitleColor(0xffffffff);
    actionBar.setItemsColor(0xffffffff, false);
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("CropImage", R.string.CropImage));
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (delegate != null && !doneButtonPressed) {
                    Bitmap bitmap = view.getBitmap();
                    if (bitmap == imageToCrop) {
                        sameBitmap = true;
                    }
                    delegate.didFinishEdit(bitmap);
                    doneButtonPressed = true;
                }
                finishFragment();
            }
        }
    });
    ActionBarMenu menu = actionBar.createMenu();
    menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56), LocaleController.getString("Done", R.string.Done));
    fragmentView = view = new PhotoCropView(context);
    ((PhotoCropView) fragmentView).freeform = getArguments().getBoolean("freeform", false);
    fragmentView.setLayoutParams(new FrameLayout.LayoutParams(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    return fragmentView;
}
Also used : Bitmap(android.graphics.Bitmap) FrameLayout(android.widget.FrameLayout) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) ActionBar(org.telegram.ui.ActionBar.ActionBar) Paint(android.graphics.Paint)

Example 59 with ActionBarMenu

use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.

the class PollCreateActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    if (quizOnly == 1) {
        actionBar.setTitle(LocaleController.getString("NewQuiz", R.string.NewQuiz));
    } else {
        actionBar.setTitle(LocaleController.getString("NewPoll", R.string.NewPoll));
    }
    if (AndroidUtilities.isTablet()) {
        actionBar.setOccupyStatusBar(false);
    }
    actionBar.setAllowOverlayTitle(true);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                if (checkDiscard()) {
                    finishFragment();
                }
            } else if (id == done_button) {
                if (quizPoll && doneItem.getAlpha() != 1.0f) {
                    int checksCount = 0;
                    for (int a = 0; a < answersChecks.length; a++) {
                        if (!TextUtils.isEmpty(ChatAttachAlertPollLayout.getFixedString(answers[a])) && answersChecks[a]) {
                            checksCount++;
                        }
                    }
                    if (checksCount <= 0) {
                        showQuizHint();
                    }
                    return;
                }
                TLRPC.TL_messageMediaPoll poll = new TLRPC.TL_messageMediaPoll();
                poll.poll = new TLRPC.TL_poll();
                poll.poll.multiple_choice = multipleChoise;
                poll.poll.quiz = quizPoll;
                poll.poll.public_voters = !anonymousPoll;
                poll.poll.question = ChatAttachAlertPollLayout.getFixedString(questionString).toString();
                SerializedData serializedData = new SerializedData(10);
                for (int a = 0; a < answers.length; a++) {
                    if (TextUtils.isEmpty(ChatAttachAlertPollLayout.getFixedString(answers[a]))) {
                        continue;
                    }
                    TLRPC.TL_pollAnswer answer = new TLRPC.TL_pollAnswer();
                    answer.text = ChatAttachAlertPollLayout.getFixedString(answers[a]).toString();
                    answer.option = new byte[1];
                    answer.option[0] = (byte) (48 + poll.poll.answers.size());
                    poll.poll.answers.add(answer);
                    if ((multipleChoise || quizPoll) && answersChecks[a]) {
                        serializedData.writeByte(answer.option[0]);
                    }
                }
                HashMap<String, String> params = new HashMap<>();
                params.put("answers", Utilities.bytesToHex(serializedData.toByteArray()));
                poll.results = new TLRPC.TL_pollResults();
                CharSequence solution = ChatAttachAlertPollLayout.getFixedString(solutionString);
                if (solution != null) {
                    poll.results.solution = solution.toString();
                    CharSequence[] message = new CharSequence[] { solution };
                    ArrayList<TLRPC.MessageEntity> entities = getMediaDataController().getEntities(message, true);
                    if (entities != null && !entities.isEmpty()) {
                        poll.results.solution_entities = entities;
                    }
                    if (!TextUtils.isEmpty(poll.results.solution)) {
                        poll.results.flags |= 16;
                    }
                }
                if (parentFragment.isInScheduleMode()) {
                    AlertsCreator.createScheduleDatePickerDialog(getParentActivity(), parentFragment.getDialogId(), (notify, scheduleDate) -> {
                        delegate.sendPoll(poll, params, notify, scheduleDate);
                        finishFragment();
                    });
                } else {
                    delegate.sendPoll(poll, params, true, 0);
                    finishFragment();
                }
            }
        }
    });
    ActionBarMenu menu = actionBar.createMenu();
    doneItem = menu.addItem(done_button, LocaleController.getString("Create", R.string.Create).toUpperCase());
    listAdapter = new ListAdapter(context);
    fragmentView = new FrameLayout(context);
    fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    listView = new RecyclerListView(context) {

        @Override
        protected void requestChildOnScreen(View child, View focused) {
            if (!(child instanceof PollEditTextCell)) {
                return;
            }
            super.requestChildOnScreen(child, focused);
        }

        @Override
        public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
            rectangle.bottom += AndroidUtilities.dp(60);
            return super.requestChildRectangleOnScreen(child, rectangle, immediate);
        }
    };
    listView.setVerticalScrollBarEnabled(false);
    ((DefaultItemAnimator) listView.getItemAnimator()).setDelayAnimations(false);
    listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new TouchHelperCallback());
    itemTouchHelper.attachToRecyclerView(listView);
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener((view, position) -> {
        if (position == addAnswerRow) {
            addNewField();
        } else if (view instanceof TextCheckCell) {
            TextCheckCell cell = (TextCheckCell) view;
            boolean checked;
            boolean wasChecksBefore = quizPoll;
            if (position == anonymousRow) {
                checked = anonymousPoll = !anonymousPoll;
            } else if (position == multipleRow) {
                checked = multipleChoise = !multipleChoise;
                if (multipleChoise && quizPoll) {
                    int prevSolutionRow = solutionRow;
                    quizPoll = false;
                    updateRows();
                    RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(quizRow);
                    if (holder != null) {
                        ((TextCheckCell) holder.itemView).setChecked(false);
                    } else {
                        listAdapter.notifyItemChanged(quizRow);
                    }
                    listAdapter.notifyItemRangeRemoved(prevSolutionRow, 2);
                }
            } else {
                if (quizOnly != 0) {
                    return;
                }
                checked = quizPoll = !quizPoll;
                int prevSolutionRow = solutionRow;
                updateRows();
                if (quizPoll) {
                    listAdapter.notifyItemRangeInserted(solutionRow, 2);
                } else {
                    listAdapter.notifyItemRangeRemoved(prevSolutionRow, 2);
                }
                if (quizPoll && multipleChoise) {
                    multipleChoise = false;
                    RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(multipleRow);
                    if (holder != null) {
                        ((TextCheckCell) holder.itemView).setChecked(false);
                    } else {
                        listAdapter.notifyItemChanged(multipleRow);
                    }
                }
                if (quizPoll) {
                    boolean was = false;
                    for (int a = 0; a < answersChecks.length; a++) {
                        if (was) {
                            answersChecks[a] = false;
                        } else if (answersChecks[a]) {
                            was = true;
                        }
                    }
                }
            }
            if (hintShowed && !quizPoll) {
                hintView.hide();
            }
            int count = listView.getChildCount();
            for (int a = answerStartRow; a < answerStartRow + answersCount; a++) {
                RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(a);
                if (holder != null && holder.itemView instanceof PollEditTextCell) {
                    PollEditTextCell pollEditTextCell = (PollEditTextCell) holder.itemView;
                    pollEditTextCell.setShowCheckBox(quizPoll, true);
                    pollEditTextCell.setChecked(answersChecks[a - answerStartRow], wasChecksBefore);
                    if (pollEditTextCell.getTop() > AndroidUtilities.dp(40) && position == quizRow && !hintShowed) {
                        hintView.showForView(pollEditTextCell.getCheckBox(), true);
                        hintShowed = true;
                    }
                }
            }
            cell.setChecked(checked);
            checkDoneButton();
        }
    });
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (dy != 0 && hintView != null) {
                hintView.hide();
            }
        }
    });
    hintView = new HintView(context, 4);
    hintView.setText(LocaleController.getString("PollTapToSelect", R.string.PollTapToSelect));
    hintView.setAlpha(0.0f);
    hintView.setVisibility(View.INVISIBLE);
    frameLayout.addView(hintView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 19, 0, 19, 0));
    checkDoneButton();
    return fragmentView;
}
Also used : HashMap(java.util.HashMap) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TLRPC(org.telegram.tgnet.TLRPC) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) ActionBar(org.telegram.ui.ActionBar.ActionBar) Rect(android.graphics.Rect) SerializedData(org.telegram.tgnet.SerializedData) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) HintView(org.telegram.ui.Components.HintView) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) HintView(org.telegram.ui.Components.HintView) PollEditTextCell(org.telegram.ui.Cells.PollEditTextCell) FrameLayout(android.widget.FrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 60 with ActionBarMenu

use of org.telegram.ui.ActionBar.ActionBarMenu in project Telegram-FOSS by Telegram-FOSS-Team.

the class TwoStepVerificationSetupActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackgroundDrawable(null);
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(false);
    actionBar.setTitleColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    actionBar.setItemsColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2), false);
    actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_actionBarWhiteSelector), false);
    actionBar.setCastShadows(false);
    actionBar.setAddToContainer(false);
    if (!AndroidUtilities.isTablet()) {
        actionBar.showActionModeTop();
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                if (otherwiseReloginDays >= 0 && parentLayout.fragmentsStack.size() == 1) {
                    showSetForcePasswordAlert();
                } else {
                    finishFragment();
                }
            } else if (id == item_resend) {
                TLRPC.TL_account_resendPasswordEmail req = new TLRPC.TL_account_resendPasswordEmail();
                ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
                });
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setMessage(LocaleController.getString("ResendCodeInfo", R.string.ResendCodeInfo));
                builder.setTitle(LocaleController.getString("TwoStepVerificationTitle", R.string.TwoStepVerificationTitle));
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                showDialog(builder.create());
            } else if (id == item_abort) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                String text;
                if (currentPassword != null && currentPassword.has_password) {
                    text = LocaleController.getString("CancelEmailQuestion", R.string.CancelEmailQuestion);
                } else {
                    text = LocaleController.getString("CancelPasswordQuestion", R.string.CancelPasswordQuestion);
                }
                String title = LocaleController.getString("CancelEmailQuestionTitle", R.string.CancelEmailQuestionTitle);
                String buttonText = LocaleController.getString("Abort", R.string.Abort);
                builder.setMessage(text);
                builder.setTitle(title);
                builder.setPositiveButton(buttonText, (dialogInterface, i) -> setNewPassword(true));
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                AlertDialog alertDialog = builder.create();
                showDialog(alertDialog);
                TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
                if (button != null) {
                    button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
                }
            }
        }
    });
    if (currentType == TYPE_EMAIL_CONFIRM) {
        ActionBarMenu menu = actionBar.createMenu();
        ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other);
        item.addSubItem(item_resend, LocaleController.getString("ResendCode", R.string.ResendCode));
        item.addSubItem(item_abort, LocaleController.getString("AbortPasswordMenu", R.string.AbortPasswordMenu));
    }
    topButton = new TextView(context);
    topButton.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText2));
    topButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    topButton.setGravity(Gravity.CENTER_VERTICAL);
    topButton.setVisibility(View.GONE);
    actionBar.addView(topButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.RIGHT, 0, 0, 22, 0));
    topButton.setOnClickListener(v -> {
        if (currentType == TYPE_ENTER_FIRST) {
            needShowProgress();
            TLRPC.TL_auth_recoverPassword req = new TLRPC.TL_auth_recoverPassword();
            req.code = emailCode;
            getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                needHideProgress();
                if (error == null) {
                    getMessagesController().removeSuggestion(0, "VALIDATE_PASSWORD");
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> {
                        for (int a = 0, N = fragmentsToClose.size(); a < N; a++) {
                            fragmentsToClose.get(a).removeSelfFromStack();
                        }
                        NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.twoStepPasswordChanged);
                        finishFragment();
                    });
                    builder.setMessage(LocaleController.getString("PasswordReset", R.string.PasswordReset));
                    builder.setTitle(LocaleController.getString("TwoStepVerificationTitle", R.string.TwoStepVerificationTitle));
                    Dialog dialog = showDialog(builder.create());
                    if (dialog != null) {
                        dialog.setCanceledOnTouchOutside(false);
                        dialog.setCancelable(false);
                    }
                } else {
                    if (error.text.startsWith("FLOOD_WAIT")) {
                        int time = Utilities.parseInt(error.text);
                        String timeString;
                        if (time < 60) {
                            timeString = LocaleController.formatPluralString("Seconds", time);
                        } else {
                            timeString = LocaleController.formatPluralString("Minutes", time / 60);
                        }
                        showAlertWithText(LocaleController.getString("TwoStepVerificationTitle", R.string.TwoStepVerificationTitle), LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString));
                    } else {
                        showAlertWithText(LocaleController.getString("TwoStepVerificationTitle", R.string.TwoStepVerificationTitle), error.text);
                    }
                }
            }));
        } else if (currentType == TYPE_ENTER_EMAIL) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setMessage(LocaleController.getString("YourEmailSkipWarningText", R.string.YourEmailSkipWarningText));
            builder.setTitle(LocaleController.getString("YourEmailSkipWarning", R.string.YourEmailSkipWarning));
            builder.setPositiveButton(LocaleController.getString("YourEmailSkip", R.string.YourEmailSkip), (dialogInterface, i) -> {
                email = "";
                setNewPassword(false);
            });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            AlertDialog alertDialog = builder.create();
            showDialog(alertDialog);
            TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
            if (button != null) {
                button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
            }
        } else if (currentType == TYPE_ENTER_HINT) {
            onHintDone();
        }
    });
    imageView = new RLottieImageView(context);
    imageView.setScaleType(ImageView.ScaleType.CENTER);
    titleTextView = new TextView(context);
    titleTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    titleTextView.setGravity(Gravity.CENTER_HORIZONTAL);
    titleTextView.setPadding(AndroidUtilities.dp(32), 0, AndroidUtilities.dp(32), 0);
    titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 24);
    descriptionText = new TextView(context);
    descriptionText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
    descriptionText.setGravity(Gravity.CENTER_HORIZONTAL);
    descriptionText.setLineSpacing(AndroidUtilities.dp(2), 1);
    descriptionText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    descriptionText.setVisibility(View.GONE);
    descriptionText.setPadding(AndroidUtilities.dp(32), 0, AndroidUtilities.dp(32), 0);
    descriptionText2 = new TextView(context);
    descriptionText2.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
    descriptionText2.setGravity(Gravity.CENTER_HORIZONTAL);
    descriptionText2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    descriptionText2.setLineSpacing(AndroidUtilities.dp(2), 1);
    descriptionText2.setPadding(AndroidUtilities.dp(32), 0, AndroidUtilities.dp(32), 0);
    descriptionText2.setVisibility(View.GONE);
    descriptionText2.setOnClickListener(v -> {
        if (currentType == TYPE_VERIFY) {
            TwoStepVerificationActivity fragment = new TwoStepVerificationActivity();
            fragment.setForgotPasswordOnShow();
            fragment.setPassword(currentPassword);
            fragment.setBlockingAlert(otherwiseReloginDays);
            presentFragment(fragment, true);
        }
    });
    buttonTextView = new TextView(context);
    buttonTextView.setMinWidth(AndroidUtilities.dp(220));
    buttonTextView.setPadding(AndroidUtilities.dp(34), 0, AndroidUtilities.dp(34), 0);
    buttonTextView.setGravity(Gravity.CENTER);
    buttonTextView.setTextColor(Theme.getColor(Theme.key_featuredStickers_buttonText));
    buttonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    buttonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    buttonTextView.setBackgroundDrawable(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(4), Theme.getColor(Theme.key_featuredStickers_addButton), Theme.getColor(Theme.key_featuredStickers_addButtonPressed)));
    buttonTextView.setOnClickListener(v -> {
        if (getParentActivity() == null) {
            return;
        }
        switch(currentType) {
            case TYPE_INTRO:
                {
                    if (currentPassword == null) {
                        needShowProgress();
                        doneAfterPasswordLoad = true;
                        return;
                    }
                    TwoStepVerificationSetupActivity fragment = new TwoStepVerificationSetupActivity(currentAccount, TYPE_ENTER_FIRST, currentPassword);
                    fragment.closeAfterSet = closeAfterSet;
                    fragment.setBlockingAlert(otherwiseReloginDays);
                    presentFragment(fragment, true);
                    break;
                }
            case TYPE_PASSWORD_SET:
                {
                    if (closeAfterSet) {
                        finishFragment();
                    } else {
                        TwoStepVerificationActivity fragment = new TwoStepVerificationActivity();
                        fragment.setCurrentPasswordParams(currentPassword, currentPasswordHash, currentSecretId, currentSecret);
                        fragment.setBlockingAlert(otherwiseReloginDays);
                        presentFragment(fragment, true);
                    }
                    break;
                }
            case TYPE_VERIFY_OK:
                {
                    finishFragment();
                    break;
                }
            case TYPE_VERIFY:
                {
                    if (currentPassword == null) {
                        needShowProgress();
                        doneAfterPasswordLoad = true;
                        return;
                    }
                    String oldPassword = passwordEditText.getText().toString();
                    if (oldPassword.length() == 0) {
                        onFieldError(passwordEditText, false);
                        return;
                    }
                    final byte[] oldPasswordBytes = AndroidUtilities.getStringBytes(oldPassword);
                    needShowProgress();
                    Utilities.globalQueue.postRunnable(() -> {
                        final TLRPC.TL_account_getPasswordSettings req = new TLRPC.TL_account_getPasswordSettings();
                        final byte[] x_bytes;
                        if (currentPassword.current_algo instanceof TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) {
                            TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow algo = (TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) currentPassword.current_algo;
                            x_bytes = SRPHelper.getX(oldPasswordBytes, algo);
                        } else {
                            x_bytes = null;
                        }
                        RequestDelegate requestDelegate = (response, error) -> {
                            if (error == null) {
                                AndroidUtilities.runOnUIThread(() -> {
                                    needHideProgress();
                                    currentPasswordHash = x_bytes;
                                    getMessagesController().removeSuggestion(0, "VALIDATE_PASSWORD");
                                    TwoStepVerificationSetupActivity fragment = new TwoStepVerificationSetupActivity(TYPE_VERIFY_OK, currentPassword);
                                    fragment.setBlockingAlert(otherwiseReloginDays);
                                    presentFragment(fragment, true);
                                });
                            } else {
                                AndroidUtilities.runOnUIThread(() -> {
                                    if ("SRP_ID_INVALID".equals(error.text)) {
                                        TLRPC.TL_account_getPassword getPasswordReq = new TLRPC.TL_account_getPassword();
                                        ConnectionsManager.getInstance(currentAccount).sendRequest(getPasswordReq, (response2, error2) -> AndroidUtilities.runOnUIThread(() -> {
                                            if (error2 == null) {
                                                currentPassword = (TLRPC.TL_account_password) response2;
                                                TwoStepVerificationActivity.initPasswordNewAlgo(currentPassword);
                                                NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.didSetOrRemoveTwoStepPassword, currentPassword);
                                                buttonTextView.callOnClick();
                                            }
                                        }), ConnectionsManager.RequestFlagWithoutLogin);
                                        return;
                                    }
                                    needHideProgress();
                                    if ("PASSWORD_HASH_INVALID".equals(error.text)) {
                                        descriptionText.setText(LocaleController.getString("CheckPasswordWrong", R.string.CheckPasswordWrong));
                                        descriptionText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4));
                                        onFieldError(passwordEditText, true);
                                        showDoneButton(false);
                                    } else if (error.text.startsWith("FLOOD_WAIT")) {
                                        int time = Utilities.parseInt(error.text);
                                        String timeString;
                                        if (time < 60) {
                                            timeString = LocaleController.formatPluralString("Seconds", time);
                                        } else {
                                            timeString = LocaleController.formatPluralString("Minutes", time / 60);
                                        }
                                        showAlertWithText(LocaleController.getString("AppName", R.string.AppName), LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString));
                                    } else {
                                        showAlertWithText(LocaleController.getString("AppName", R.string.AppName), error.text);
                                    }
                                });
                            }
                        };
                        if (currentPassword.current_algo instanceof TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) {
                            TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow algo = (TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) currentPassword.current_algo;
                            req.password = SRPHelper.startCheck(x_bytes, currentPassword.srp_id, currentPassword.srp_B, algo);
                            if (req.password == null) {
                                TLRPC.TL_error error = new TLRPC.TL_error();
                                error.text = "ALGO_INVALID";
                                requestDelegate.run(null, error);
                                return;
                            }
                            ConnectionsManager.getInstance(currentAccount).sendRequest(req, requestDelegate, ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
                        } else {
                            TLRPC.TL_error error = new TLRPC.TL_error();
                            error.text = "PASSWORD_HASH_INVALID";
                            requestDelegate.run(null, error);
                        }
                    });
                    break;
                }
            case TYPE_ENTER_FIRST:
                {
                    if (passwordEditText.length() == 0) {
                        onFieldError(passwordEditText, false);
                        return;
                    }
                    TwoStepVerificationSetupActivity fragment = new TwoStepVerificationSetupActivity(currentAccount, TYPE_ENTER_SECOND, currentPassword);
                    fragment.setCurrentPasswordParams(currentPasswordHash, currentSecretId, currentSecret, emailOnly);
                    fragment.setCurrentEmailCode(emailCode);
                    fragment.firstPassword = passwordEditText.getText().toString();
                    fragment.fragmentsToClose.addAll(fragmentsToClose);
                    fragment.fragmentsToClose.add(this);
                    fragment.closeAfterSet = closeAfterSet;
                    fragment.setBlockingAlert(otherwiseReloginDays);
                    presentFragment(fragment);
                    break;
                }
            case TYPE_ENTER_SECOND:
                {
                    if (!firstPassword.equals(passwordEditText.getText().toString())) {
                        try {
                            Toast.makeText(getParentActivity(), LocaleController.getString("PasswordDoNotMatch", R.string.PasswordDoNotMatch), Toast.LENGTH_SHORT).show();
                        } catch (Exception e) {
                            FileLog.e(e);
                        }
                        onFieldError(passwordEditText, false);
                        return;
                    }
                    TwoStepVerificationSetupActivity fragment = new TwoStepVerificationSetupActivity(currentAccount, TYPE_ENTER_HINT, currentPassword);
                    fragment.setCurrentPasswordParams(currentPasswordHash, currentSecretId, currentSecret, emailOnly);
                    fragment.setCurrentEmailCode(emailCode);
                    fragment.firstPassword = firstPassword;
                    fragment.fragmentsToClose.addAll(fragmentsToClose);
                    fragment.fragmentsToClose.add(this);
                    fragment.closeAfterSet = closeAfterSet;
                    fragment.setBlockingAlert(otherwiseReloginDays);
                    presentFragment(fragment);
                    break;
                }
            case TYPE_ENTER_HINT:
                {
                    String hint = passwordEditText.getText().toString();
                    if (hint.toLowerCase().equals(firstPassword.toLowerCase())) {
                        try {
                            Toast.makeText(getParentActivity(), LocaleController.getString("PasswordAsHintError", R.string.PasswordAsHintError), Toast.LENGTH_SHORT).show();
                        } catch (Exception e) {
                            FileLog.e(e);
                        }
                        onFieldError(passwordEditText, false);
                        return;
                    }
                    onHintDone();
                    break;
                }
            case TYPE_ENTER_EMAIL:
                {
                    email = passwordEditText.getText().toString();
                    if (!isValidEmail(email)) {
                        onFieldError(passwordEditText, false);
                        return;
                    }
                    setNewPassword(false);
                    break;
                }
            case TYPE_EMAIL_RECOVERY:
                {
                    String code = passwordEditText.getText().toString();
                    if (code.length() == 0) {
                        onFieldError(passwordEditText, false);
                        return;
                    }
                    TLRPC.TL_auth_checkRecoveryPassword req = new TLRPC.TL_auth_checkRecoveryPassword();
                    req.code = code;
                    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                        if (response instanceof TLRPC.TL_boolTrue) {
                            TwoStepVerificationSetupActivity fragment = new TwoStepVerificationSetupActivity(currentAccount, TYPE_ENTER_FIRST, currentPassword);
                            fragment.fragmentsToClose.addAll(fragmentsToClose);
                            fragment.addFragmentToClose(TwoStepVerificationSetupActivity.this);
                            fragment.setCurrentEmailCode(code);
                            fragment.setBlockingAlert(otherwiseReloginDays);
                            presentFragment(fragment, true);
                        } else {
                            if (error == null || error.text.startsWith("CODE_INVALID")) {
                                onFieldError(passwordEditText, true);
                            } else if (error.text.startsWith("FLOOD_WAIT")) {
                                int time = Utilities.parseInt(error.text);
                                String timeString;
                                if (time < 60) {
                                    timeString = LocaleController.formatPluralString("Seconds", time);
                                } else {
                                    timeString = LocaleController.formatPluralString("Minutes", time / 60);
                                }
                                showAlertWithText(LocaleController.getString("TwoStepVerificationTitle", R.string.TwoStepVerificationTitle), LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString));
                            } else {
                                showAlertWithText(LocaleController.getString("TwoStepVerificationTitle", R.string.TwoStepVerificationTitle), error.text);
                            }
                        }
                    }), ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
                    break;
                }
            case TYPE_EMAIL_CONFIRM:
                {
                    if (passwordEditText.length() == 0) {
                        onFieldError(passwordEditText, false);
                        return;
                    }
                    TLRPC.TL_account_confirmPasswordEmail req = new TLRPC.TL_account_confirmPasswordEmail();
                    req.code = passwordEditText.getText().toString();
                    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                        needHideProgress();
                        if (error == null) {
                            if (getParentActivity() == null) {
                                return;
                            }
                            if (currentPassword.has_password) {
                                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialogInterface, i) -> {
                                    for (int a = 0, N = fragmentsToClose.size(); a < N; a++) {
                                        fragmentsToClose.get(a).removeSelfFromStack();
                                    }
                                    NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.twoStepPasswordChanged, currentPasswordHash, currentPassword.new_algo, currentPassword.new_secure_algo, currentPassword.secure_random, email, hint, null, firstPassword);
                                    TwoStepVerificationActivity fragment = new TwoStepVerificationActivity();
                                    currentPassword.has_password = true;
                                    currentPassword.has_recovery = true;
                                    currentPassword.email_unconfirmed_pattern = "";
                                    fragment.setCurrentPasswordParams(currentPassword, currentPasswordHash, currentSecretId, currentSecret);
                                    fragment.setBlockingAlert(otherwiseReloginDays);
                                    presentFragment(fragment, true);
                                    NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.didSetOrRemoveTwoStepPassword, currentPassword);
                                });
                                if (currentPassword.has_recovery) {
                                    builder.setMessage(LocaleController.getString("YourEmailSuccessChangedText", R.string.YourEmailSuccessChangedText));
                                } else {
                                    builder.setMessage(LocaleController.getString("YourEmailSuccessText", R.string.YourEmailSuccessText));
                                }
                                builder.setTitle(LocaleController.getString("YourPasswordSuccess", R.string.YourPasswordSuccess));
                                Dialog dialog = showDialog(builder.create());
                                if (dialog != null) {
                                    dialog.setCanceledOnTouchOutside(false);
                                    dialog.setCancelable(false);
                                }
                            } else {
                                for (int a = 0, N = fragmentsToClose.size(); a < N; a++) {
                                    fragmentsToClose.get(a).removeSelfFromStack();
                                }
                                currentPassword.has_password = true;
                                currentPassword.has_recovery = true;
                                currentPassword.email_unconfirmed_pattern = "";
                                TwoStepVerificationSetupActivity fragment = new TwoStepVerificationSetupActivity(TYPE_PASSWORD_SET, currentPassword);
                                fragment.setCurrentPasswordParams(currentPasswordHash, currentSecretId, currentSecret, emailOnly);
                                fragment.fragmentsToClose.addAll(fragmentsToClose);
                                fragment.closeAfterSet = closeAfterSet;
                                fragment.setBlockingAlert(otherwiseReloginDays);
                                presentFragment(fragment, true);
                                NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.twoStepPasswordChanged, currentPasswordHash, currentPassword.new_algo, currentPassword.new_secure_algo, currentPassword.secure_random, email, hint, null, firstPassword);
                                NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.didSetOrRemoveTwoStepPassword, currentPassword);
                            }
                        } else {
                            if (error.text.startsWith("CODE_INVALID")) {
                                onFieldError(passwordEditText, true);
                            } else if (error.text.startsWith("FLOOD_WAIT")) {
                                int time = Utilities.parseInt(error.text);
                                String timeString;
                                if (time < 60) {
                                    timeString = LocaleController.formatPluralString("Seconds", time);
                                } else {
                                    timeString = LocaleController.formatPluralString("Minutes", time / 60);
                                }
                                showAlertWithText(LocaleController.getString("AppName", R.string.AppName), LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString));
                            } else {
                                showAlertWithText(LocaleController.getString("AppName", R.string.AppName), error.text);
                            }
                        }
                    }), ConnectionsManager.RequestFlagFailOnServerErrors | ConnectionsManager.RequestFlagWithoutLogin);
                    needShowProgress();
                }
        }
    });
    switch(currentType) {
        case TYPE_INTRO:
        case TYPE_PASSWORD_SET:
        case TYPE_VERIFY_OK:
            {
                ViewGroup container = new ViewGroup(context) {

                    @Override
                    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                        int width = MeasureSpec.getSize(widthMeasureSpec);
                        int height = MeasureSpec.getSize(heightMeasureSpec);
                        actionBar.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), heightMeasureSpec);
                        if (width > height) {
                            imageView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.45f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int) (height * 0.68f), MeasureSpec.EXACTLY));
                            titleTextView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
                            descriptionText.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
                            descriptionText2.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
                            buttonTextView.measure(MeasureSpec.makeMeasureSpec((int) (width * 0.6f), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(42), MeasureSpec.EXACTLY));
                        } else {
                            imageView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int) (height * 0.399f), MeasureSpec.EXACTLY));
                            titleTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
                            descriptionText.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
                            descriptionText2.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.UNSPECIFIED));
                            buttonTextView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(42), MeasureSpec.EXACTLY));
                        }
                        setMeasuredDimension(width, height);
                    }

                    @Override
                    protected void onLayout(boolean changed, int l, int t, int r, int b) {
                        actionBar.layout(0, 0, r, actionBar.getMeasuredHeight());
                        int width = r - l;
                        int height = b - t;
                        if (r > b) {
                            int y = (height - imageView.getMeasuredHeight()) / 2;
                            imageView.layout(0, y, imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight());
                            int x = (int) (width * 0.4f);
                            y = (int) (height * 0.22f);
                            titleTextView.layout(x, y, x + titleTextView.getMeasuredWidth(), y + titleTextView.getMeasuredHeight());
                            x = (int) (width * 0.4f);
                            y = (int) (height * 0.39f);
                            descriptionText.layout(x, y, x + descriptionText.getMeasuredWidth(), y + descriptionText.getMeasuredHeight());
                            x = (int) (width * 0.4f + (width * 0.6f - buttonTextView.getMeasuredWidth()) / 2);
                            y = (int) (height * 0.64f);
                            buttonTextView.layout(x, y, x + buttonTextView.getMeasuredWidth(), y + buttonTextView.getMeasuredHeight());
                        } else {
                            int y = (int) (height * 0.148f);
                            imageView.layout(0, y, imageView.getMeasuredWidth(), y + imageView.getMeasuredHeight());
                            y = (int) (height * 0.458f);
                            titleTextView.layout(0, y, titleTextView.getMeasuredWidth(), y + titleTextView.getMeasuredHeight());
                            y += titleTextView.getMeasuredHeight() + AndroidUtilities.dp(12);
                            descriptionText.layout(0, y, descriptionText.getMeasuredWidth(), y + descriptionText.getMeasuredHeight());
                            int x = (width - buttonTextView.getMeasuredWidth()) / 2;
                            y = (int) (height * 0.791f);
                            buttonTextView.layout(x, y, x + buttonTextView.getMeasuredWidth(), y + buttonTextView.getMeasuredHeight());
                        }
                    }
                };
                container.setOnTouchListener((v, event) -> true);
                container.addView(actionBar);
                container.addView(imageView);
                container.addView(titleTextView);
                container.addView(descriptionText);
                container.addView(buttonTextView);
                fragmentView = container;
                break;
            }
        case TYPE_VERIFY:
        case TYPE_ENTER_FIRST:
        case TYPE_ENTER_SECOND:
        case TYPE_EMAIL_CONFIRM:
        case TYPE_EMAIL_RECOVERY:
        case TYPE_ENTER_HINT:
        case TYPE_ENTER_EMAIL:
            {
                ViewGroup container = new ViewGroup(context) {

                    @Override
                    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                        int width = MeasureSpec.getSize(widthMeasureSpec);
                        int height = MeasureSpec.getSize(heightMeasureSpec);
                        if (topButton != null) {
                            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) topButton.getLayoutParams();
                            layoutParams.topMargin = AndroidUtilities.statusBarHeight;
                        }
                        actionBar.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), heightMeasureSpec);
                        actionBarBackground.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(actionBar.getMeasuredHeight() + AndroidUtilities.dp(3), MeasureSpec.EXACTLY));
                        scrollView.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), heightMeasureSpec);
                        setMeasuredDimension(width, height);
                    }

                    @Override
                    protected void onLayout(boolean changed, int l, int t, int r, int b) {
                        actionBar.layout(0, 0, actionBar.getMeasuredWidth(), actionBar.getMeasuredHeight());
                        actionBarBackground.layout(0, 0, actionBarBackground.getMeasuredWidth(), actionBarBackground.getMeasuredHeight());
                        scrollView.layout(0, 0, scrollView.getMeasuredWidth(), scrollView.getMeasuredHeight());
                    }
                };
                scrollView = new ScrollView(context) {

                    private int[] location = new int[2];

                    private Rect tempRect = new Rect();

                    private boolean isLayoutDirty = true;

                    private int scrollingUp;

                    @Override
                    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
                        super.onScrollChanged(l, t, oldl, oldt);
                        if (titleTextView == null) {
                            return;
                        }
                        titleTextView.getLocationOnScreen(location);
                        boolean show = location[1] + titleTextView.getMeasuredHeight() < actionBar.getBottom();
                        boolean visible = titleTextView.getTag() == null;
                        if (show != visible) {
                            titleTextView.setTag(show ? null : 1);
                            if (actionBarAnimator != null) {
                                actionBarAnimator.cancel();
                                actionBarAnimator = null;
                            }
                            actionBarAnimator = new AnimatorSet();
                            actionBarAnimator.playTogether(ObjectAnimator.ofFloat(actionBarBackground, View.ALPHA, show ? 1.0f : 0.0f), ObjectAnimator.ofFloat(actionBar.getTitleTextView(), View.ALPHA, show ? 1.0f : 0.0f));
                            actionBarAnimator.setDuration(150);
                            actionBarAnimator.addListener(new AnimatorListenerAdapter() {

                                @Override
                                public void onAnimationEnd(Animator animation) {
                                    if (animation.equals(actionBarAnimator)) {
                                        actionBarAnimator = null;
                                    }
                                }
                            });
                            actionBarAnimator.start();
                        }
                    }

                    @Override
                    public void scrollToDescendant(View child) {
                        child.getDrawingRect(tempRect);
                        offsetDescendantRectToMyCoords(child, tempRect);
                        tempRect.bottom += AndroidUtilities.dp(120);
                        int scrollDelta = computeScrollDeltaToGetChildRectOnScreen(tempRect);
                        if (scrollDelta < 0) {
                            scrollDelta -= (scrollingUp = (getMeasuredHeight() - child.getMeasuredHeight()) / 2);
                        } else {
                            scrollingUp = 0;
                        }
                        if (scrollDelta != 0) {
                            smoothScrollBy(0, scrollDelta);
                        }
                    }

                    @Override
                    public void requestChildFocus(View child, View focused) {
                        if (Build.VERSION.SDK_INT < 29) {
                            if (focused != null && !isLayoutDirty) {
                                scrollToDescendant(focused);
                            }
                        }
                        super.requestChildFocus(child, focused);
                    }

                    @Override
                    public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
                        if (Build.VERSION.SDK_INT < 23) {
                            rectangle.bottom += AndroidUtilities.dp(120);
                            if (scrollingUp != 0) {
                                rectangle.top -= scrollingUp;
                                rectangle.bottom -= scrollingUp;
                                scrollingUp = 0;
                            }
                        }
                        return super.requestChildRectangleOnScreen(child, rectangle, immediate);
                    }

                    @Override
                    public void requestLayout() {
                        isLayoutDirty = true;
                        super.requestLayout();
                    }

                    @Override
                    protected void onLayout(boolean changed, int l, int t, int r, int b) {
                        isLayoutDirty = false;
                        super.onLayout(changed, l, t, r, b);
                    }
                };
                scrollView.setVerticalScrollBarEnabled(false);
                container.addView(scrollView);
                LinearLayout scrollViewLinearLayout = new LinearLayout(context);
                scrollViewLinearLayout.setOrientation(LinearLayout.VERTICAL);
                scrollView.addView(scrollViewLinearLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
                scrollViewLinearLayout.addView(imageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, 69, 0, 0));
                scrollViewLinearLayout.addView(titleTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, 8, 0, 0));
                scrollViewLinearLayout.addView(descriptionText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, 9, 0, 0));
                FrameLayout frameLayout = new FrameLayout(context);
                scrollViewLinearLayout.addView(frameLayout, LayoutHelper.createLinear(220, 36, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 40, 32, 40, 0));
                passwordEditText = new EditTextBoldCursor(context);
                passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 17);
                passwordEditText.setPadding(0, AndroidUtilities.dp(2), 0, 0);
                passwordEditText.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
                passwordEditText.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
                passwordEditText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
                passwordEditText.setHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
                passwordEditText.setBackgroundDrawable(Theme.createEditTextDrawable(context, false));
                passwordEditText.setMaxLines(1);
                passwordEditText.setLines(1);
                passwordEditText.setGravity(Gravity.LEFT);
                passwordEditText.setCursorSize(AndroidUtilities.dp(20));
                passwordEditText.setSingleLine(true);
                passwordEditText.setCursorWidth(1.5f);
                frameLayout.addView(passwordEditText, LayoutHelper.createFrame(220, 36, Gravity.TOP | Gravity.CENTER_HORIZONTAL));
                passwordEditText.setOnEditorActionListener((textView, i, keyEvent) -> {
                    if (i == EditorInfo.IME_ACTION_NEXT || i == EditorInfo.IME_ACTION_DONE) {
                        buttonTextView.callOnClick();
                        return true;
                    }
                    return false;
                });
                passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {

                    public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                        return false;
                    }

                    public void onDestroyActionMode(ActionMode mode) {
                    }

                    public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                        return false;
                    }

                    public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                        return false;
                    }
                });
                showPasswordButton = new ImageView(context) {

                    @Override
                    public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
                        super.onInitializeAccessibilityNodeInfo(info);
                        info.setCheckable(true);
                        info.setChecked(passwordEditText.getTransformationMethod() == null);
                    }
                };
                showPasswordButton.setImageResource(R.drawable.msg_message);
                showPasswordButton.setScaleType(ImageView.ScaleType.CENTER);
                showPasswordButton.setContentDescription(LocaleController.getString("TwoStepVerificationShowPassword", R.string.TwoStepVerificationShowPassword));
                if (Build.VERSION.SDK_INT >= 21) {
                    showPasswordButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.getColor(Theme.key_listSelector)));
                }
                showPasswordButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelIcons), PorterDuff.Mode.MULTIPLY));
                showPasswordButton.setVisibility(View.GONE);
                frameLayout.addView(showPasswordButton, LayoutHelper.createFrame(36, 36, Gravity.RIGHT | Gravity.TOP, 0, -5, 0, 0));
                showPasswordButton.setOnClickListener(v -> {
                    ignoreTextChange = true;
                    if (passwordEditText.getTransformationMethod() == null) {
                        passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
                        showPasswordButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelIcons), PorterDuff.Mode.MULTIPLY));
                        if (currentType == TYPE_ENTER_FIRST) {
                            if (passwordEditText.length() > 0) {
                                animationDrawables[3].setCustomEndFrame(-1);
                                if (imageView.getAnimatedDrawable() != animationDrawables[3]) {
                                    imageView.setAnimation(animationDrawables[3]);
                                    animationDrawables[3].setCurrentFrame(18, false);
                                }
                                imageView.playAnimation();
                            }
                        }
                    } else {
                        passwordEditText.setTransformationMethod(null);
                        showPasswordButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelSend), PorterDuff.Mode.MULTIPLY));
                        if (currentType == TYPE_ENTER_FIRST) {
                            if (passwordEditText.length() > 0) {
                                animationDrawables[3].setCustomEndFrame(18);
                                if (imageView.getAnimatedDrawable() != animationDrawables[3]) {
                                    imageView.setAnimation(animationDrawables[3]);
                                }
                                animationDrawables[3].setProgress(0.0f, false);
                                imageView.playAnimation();
                            }
                        }
                    }
                    passwordEditText.setSelection(passwordEditText.length());
                    ignoreTextChange = false;
                });
                FrameLayout frameLayout2 = new FrameLayout(context);
                scrollViewLinearLayout.addView(frameLayout2, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 36, 0, 22));
                frameLayout2.addView(buttonTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 42, Gravity.CENTER_HORIZONTAL | Gravity.TOP));
                frameLayout2.addView(descriptionText2, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.TOP));
                if (currentType == TYPE_EMAIL_RECOVERY) {
                    descriptionText3 = new TextView(context);
                    descriptionText3.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkText));
                    descriptionText3.setGravity(Gravity.CENTER_HORIZONTAL);
                    descriptionText3.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
                    descriptionText3.setLineSpacing(AndroidUtilities.dp(2), 1);
                    descriptionText3.setPadding(AndroidUtilities.dp(32), 0, AndroidUtilities.dp(32), 0);
                    descriptionText3.setText(LocaleController.getString("RestoreEmailTroubleNoEmail", R.string.RestoreEmailTroubleNoEmail));
                    scrollViewLinearLayout.addView(descriptionText3, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 0, 0, 0, 25));
                    descriptionText3.setOnClickListener(v -> {
                        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                        builder.setPositiveButton(LocaleController.getString("Reset", R.string.Reset), (dialog, which) -> {
                            onReset();
                            finishFragment();
                        });
                        builder.setTitle(LocaleController.getString("ResetPassword", R.string.ResetPassword));
                        builder.setMessage(LocaleController.getString("RestoreEmailTroubleText2", R.string.RestoreEmailTroubleText2));
                        showDialog(builder.create());
                    });
                }
                fragmentView = container;
                actionBarBackground = new View(context) {

                    private Paint paint = new Paint();

                    @Override
                    protected void onDraw(Canvas canvas) {
                        paint.setColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                        int h = getMeasuredHeight() - AndroidUtilities.dp(3);
                        canvas.drawRect(0, 0, getMeasuredWidth(), h, paint);
                        parentLayout.drawHeaderShadow(canvas, h);
                    }
                };
                actionBarBackground.setAlpha(0.0f);
                container.addView(actionBarBackground);
                container.addView(actionBar);
                break;
            }
    }
    fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    switch(currentType) {
        case TYPE_INTRO:
            {
                titleTextView.setText(LocaleController.getString("TwoStepVerificationTitle", R.string.TwoStepVerificationTitle));
                descriptionText.setText(LocaleController.getString("SetAdditionalPasswordInfo", R.string.SetAdditionalPasswordInfo));
                buttonTextView.setText(LocaleController.getString("TwoStepVerificationSetPassword", R.string.TwoStepVerificationSetPassword));
                descriptionText.setVisibility(View.VISIBLE);
                imageView.setAnimation(R.raw.tsv_setup_intro, 120, 120);
                imageView.playAnimation();
                break;
            }
        case TYPE_PASSWORD_SET:
            {
                titleTextView.setText(LocaleController.getString("TwoStepVerificationPasswordSet", R.string.TwoStepVerificationPasswordSet));
                descriptionText.setText(LocaleController.getString("TwoStepVerificationPasswordSetInfo", R.string.TwoStepVerificationPasswordSetInfo));
                if (closeAfterSet) {
                    buttonTextView.setText(LocaleController.getString("TwoStepVerificationPasswordReturnPassport", R.string.TwoStepVerificationPasswordReturnPassport));
                } else {
                    buttonTextView.setText(LocaleController.getString("TwoStepVerificationPasswordReturnSettings", R.string.TwoStepVerificationPasswordReturnSettings));
                }
                descriptionText.setVisibility(View.VISIBLE);
                imageView.setAnimation(R.raw.wallet_allset, 120, 120);
                imageView.playAnimation();
                break;
            }
        case TYPE_VERIFY_OK:
            {
                titleTextView.setText(LocaleController.getString("CheckPasswordPerfect", R.string.CheckPasswordPerfect));
                descriptionText.setText(LocaleController.getString("CheckPasswordPerfectInfo", R.string.CheckPasswordPerfectInfo));
                buttonTextView.setText(LocaleController.getString("CheckPasswordBackToSettings", R.string.CheckPasswordBackToSettings));
                descriptionText.setVisibility(View.VISIBLE);
                imageView.setAnimation(R.raw.wallet_perfect, 120, 120);
                imageView.playAnimation();
                break;
            }
        case TYPE_VERIFY:
            {
                actionBar.setTitle(LocaleController.getString("PleaseEnterCurrentPassword", R.string.PleaseEnterCurrentPassword));
                titleTextView.setText(LocaleController.getString("PleaseEnterCurrentPassword", R.string.PleaseEnterCurrentPassword));
                descriptionText.setText(LocaleController.getString("CheckPasswordInfo", R.string.CheckPasswordInfo));
                descriptionText.setVisibility(View.VISIBLE);
                actionBar.getTitleTextView().setAlpha(0.0f);
                buttonTextView.setText(LocaleController.getString("CheckPassword", R.string.CheckPassword));
                descriptionText2.setText(LocaleController.getString("ForgotPassword", R.string.ForgotPassword));
                descriptionText2.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText2));
                passwordEditText.setHint(LocaleController.getString("LoginPassword", R.string.LoginPassword));
                passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
                passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
                passwordEditText.setTypeface(Typeface.DEFAULT);
                passwordEditText.setPadding(0, AndroidUtilities.dp(2), AndroidUtilities.dp(36), 0);
                imageView.setAnimation(R.raw.wallet_science, 120, 120);
                imageView.playAnimation();
                break;
            }
        case TYPE_ENTER_FIRST:
            {
                if (currentPassword.has_password) {
                    actionBar.setTitle(LocaleController.getString("PleaseEnterNewFirstPassword", R.string.PleaseEnterNewFirstPassword));
                    titleTextView.setText(LocaleController.getString("PleaseEnterNewFirstPassword", R.string.PleaseEnterNewFirstPassword));
                } else {
                    actionBar.setTitle(LocaleController.getString("PleaseEnterFirstPassword", R.string.PleaseEnterFirstPassword));
                    titleTextView.setText(LocaleController.getString("PleaseEnterFirstPassword", R.string.PleaseEnterFirstPassword));
                }
                if (!TextUtils.isEmpty(emailCode)) {
                    topButton.setVisibility(View.VISIBLE);
                    topButton.setText(LocaleController.getString("YourEmailSkip", R.string.YourEmailSkip));
                }
                actionBar.getTitleTextView().setAlpha(0.0f);
                buttonTextView.setText(LocaleController.getString("Continue", R.string.Continue));
                passwordEditText.setHint(LocaleController.getString("LoginPassword", R.string.LoginPassword));
                passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
                passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
                passwordEditText.setTypeface(Typeface.DEFAULT);
                showPasswordButton.setVisibility(View.VISIBLE);
                passwordEditText.setPadding(0, AndroidUtilities.dp(2), AndroidUtilities.dp(36), 0);
                animationDrawables = new RLottieDrawable[6];
                animationDrawables[0] = new RLottieDrawable(R.raw.tsv_setup_monkey_idle1, "" + R.raw.tsv_setup_monkey_idle1, AndroidUtilities.dp(120), AndroidUtilities.dp(120), true, null);
                animationDrawables[1] = new RLottieDrawable(R.raw.tsv_setup_monkey_idle2, "" + R.raw.tsv_setup_monkey_idle2, AndroidUtilities.dp(120), AndroidUtilities.dp(120), true, null);
                animationDrawables[2] = new RLottieDrawable(R.raw.tsv_monkey_close, "" + R.raw.tsv_monkey_close, AndroidUtilities.dp(120), AndroidUtilities.dp(120), true, null);
                animationDrawables[3] = new RLottieDrawable(R.raw.tsv_setup_monkey_peek, "" + R.raw.tsv_setup_monkey_peek, AndroidUtilities.dp(120), AndroidUtilities.dp(120), true, null);
                animationDrawables[4] = new RLottieDrawable(R.raw.tsv_setup_monkey_close_and_peek_to_idle, "" + R.raw.tsv_setup_monkey_close_and_peek_to_idle, AndroidUtilities.dp(120), AndroidUtilities.dp(120), true, null);
                animationDrawables[5] = new RLottieDrawable(R.raw.tsv_setup_monkey_close_and_peek, "" + R.raw.tsv_setup_monkey_close_and_peek, AndroidUtilities.dp(120), AndroidUtilities.dp(120), true, null);
                animationDrawables[2].setOnFinishCallback(finishCallback, 97);
                setRandomMonkeyIdleAnimation(true);
                break;
            }
        case TYPE_ENTER_SECOND:
            {
                actionBar.setTitle(LocaleController.getString("PleaseReEnterPassword", R.string.PleaseReEnterPassword));
                actionBar.getTitleTextView().setAlpha(0.0f);
                titleTextView.setText(LocaleController.getString("PleaseReEnterPassword", R.string.PleaseReEnterPassword));
                buttonTextView.setText(LocaleController.getString("Continue", R.string.Continue));
                passwordEditText.setHint(LocaleController.getString("LoginPassword", R.string.LoginPassword));
                passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
                passwordEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                passwordEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
                passwordEditText.setTypeface(Typeface.DEFAULT);
                showPasswordButton.setVisibility(View.VISIBLE);
                passwordEditText.setPadding(0, AndroidUtilities.dp(2), AndroidUtilities.dp(36), 0);
                animationDrawables = new RLottieDrawable[1];
                animationDrawables[0] = new RLottieDrawable(R.raw.tsv_setup_monkey_tracking, "" + R.raw.tsv_setup_monkey_tracking, AndroidUtilities.dp(120), AndroidUtilities.dp(120), true, null);
                animationDrawables[0].setPlayInDirectionOfCustomEndFrame(true);
                animationDrawables[0].setCustomEndFrame(19);
                imageView.setAnimation(animationDrawables[0]);
                imageView.playAnimation();
                break;
            }
        case TYPE_ENTER_HINT:
            {
                actionBar.setTitle(LocaleController.getString("PasswordHint", R.string.PasswordHint));
                actionBar.getTitleTextView().setAlpha(0.0f);
                topButton.setVisibility(View.VISIBLE);
                topButton.setText(LocaleController.getString("YourEmailSkip", R.string.YourEmailSkip));
                titleTextView.setText(LocaleController.getString("PasswordHint", R.string.PasswordHint));
                buttonTextView.setText(LocaleController.getString("Continue", R.string.Continue));
                passwordEditText.setHint(LocaleController.getString("PasswordHintPlaceholder", R.string.PasswordHintPlaceholder));
                passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
                imageView.setAnimation(R.raw.tsv_setup_hint, 120, 120);
                imageView.playAnimation();
                break;
            }
        case TYPE_ENTER_EMAIL:
            {
                actionBar.setTitle(LocaleController.getString("RecoveryEmailTitle", R.string.RecoveryEmailTitle));
                actionBar.getTitleTextView().setAlpha(0.0f);
                if (!emailOnly) {
                    topButton.setVisibility(View.VISIBLE);
                    topButton.setText(LocaleController.getString("YourEmailSkip", R.string.YourEmailSkip));
                }
                titleTextView.setText(LocaleController.getString("RecoveryEmailTitle", R.string.RecoveryEmailTitle));
                buttonTextView.setText(LocaleController.getString("Continue", R.string.Continue));
                passwordEditText.setHint(LocaleController.getString("PaymentShippingEmailPlaceholder", R.string.PaymentShippingEmailPlaceholder));
                passwordEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
                passwordEditText.setInputType(EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
                imageView.setAnimation(R.raw.tsv_setup_email_sent, 120, 120);
                imageView.playAnimation();
                break;
            }
        case TYPE_EMAIL_CONFIRM:
            {
                actionBar.setTitle(LocaleController.getString("VerificationCode", R.string.VerificationCode));
                actionBar.getTitleTextView().setAlpha(0.0f);
                titleTextView.setText(LocaleController.getString("VerificationCode", R.string.VerificationCode));
                buttonTextView.setText(LocaleController.getString("Continue", R.string.Continue));
                passwordEditText.setHint(LocaleController.getString("EnterCode", R.string.EnterCode));
                passwordEditText.setInputType(InputType.TYPE_CLASS_PHONE);
                passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
                descriptionText2.setText(LocaleController.formatString("EmailPasswordConfirmText2", R.string.EmailPasswordConfirmText2, currentPassword.email_unconfirmed_pattern != null ? currentPassword.email_unconfirmed_pattern : ""));
                descriptionText2.setVisibility(View.VISIBLE);
                buttonTextView.setVisibility(View.INVISIBLE);
                buttonTextView.setAlpha(0.0f);
                buttonTextView.setScaleX(0.9f);
                buttonTextView.setScaleY(0.9f);
                imageView.setAnimation(R.raw.tsv_setup_mail, 120, 120);
                imageView.playAnimation();
                break;
            }
        case TYPE_EMAIL_RECOVERY:
            {
                actionBar.setTitle(LocaleController.getString("PasswordRecovery", R.string.PasswordRecovery));
                actionBar.getTitleTextView().setAlpha(0.0f);
                titleTextView.setText(LocaleController.getString("PasswordRecovery", R.string.PasswordRecovery));
                buttonTextView.setText(LocaleController.getString("Continue", R.string.Continue));
                passwordEditText.setHint(LocaleController.getString("EnterCode", R.string.EnterCode));
                passwordEditText.setInputType(InputType.TYPE_CLASS_PHONE);
                passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
                descriptionText2.setText(LocaleController.formatString("RestoreEmailSent", R.string.RestoreEmailSent, currentPassword.email_unconfirmed_pattern != null ? currentPassword.email_unconfirmed_pattern : ""));
                descriptionText2.setVisibility(View.VISIBLE);
                buttonTextView.setVisibility(View.INVISIBLE);
                buttonTextView.setAlpha(0.0f);
                buttonTextView.setScaleX(0.9f);
                buttonTextView.setScaleY(0.9f);
                imageView.setAnimation(R.raw.tsv_setup_mail, 120, 120);
                imageView.playAnimation();
                break;
            }
    }
    if (passwordEditText != null) {
        passwordEditText.addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if (ignoreTextChange) {
                    return;
                }
                if (currentType == TYPE_ENTER_FIRST) {
                    RLottieDrawable currentDrawable = imageView.getAnimatedDrawable();
                    if (passwordEditText.length() > 0) {
                        if (passwordEditText.getTransformationMethod() == null) {
                            if (currentDrawable != animationDrawables[3] && currentDrawable != animationDrawables[5]) {
                                imageView.setAnimation(animationDrawables[5]);
                                animationDrawables[5].setProgress(0.0f, false);
                                imageView.playAnimation();
                            }
                        } else {
                            if (currentDrawable != animationDrawables[3]) {
                                if (currentDrawable != animationDrawables[2]) {
                                    imageView.setAnimation(animationDrawables[2]);
                                    animationDrawables[2].setCustomEndFrame(49);
                                    animationDrawables[2].setProgress(0.0f, false);
                                    imageView.playAnimation();
                                } else {
                                    if (animationDrawables[2].getCurrentFrame() < 49) {
                                        animationDrawables[2].setCustomEndFrame(49);
                                    }
                                }
                            }
                        }
                    } else {
                        if (currentDrawable == animationDrawables[3] && passwordEditText.getTransformationMethod() == null || currentDrawable == animationDrawables[5]) {
                            imageView.setAnimation(animationDrawables[4]);
                            animationDrawables[4].setProgress(0.0f, false);
                            imageView.playAnimation();
                        } else {
                            animationDrawables[2].setCustomEndFrame(-1);
                            if (currentDrawable != animationDrawables[2]) {
                                imageView.setAnimation(animationDrawables[2]);
                                animationDrawables[2].setCurrentFrame(49, false);
                            }
                            imageView.playAnimation();
                        }
                    }
                } else if (currentType == TYPE_ENTER_SECOND) {
                    try {
                        float progress = Math.min(1.0f, passwordEditText.getLayout().getLineWidth(0) / passwordEditText.getWidth());
                        animationDrawables[0].setCustomEndFrame((int) (18 + progress * (160 - 18)));
                        imageView.playAnimation();
                    } catch (Exception e) {
                        FileLog.e(e);
                    }
                } else if (currentType == TYPE_EMAIL_CONFIRM || currentType == TYPE_EMAIL_RECOVERY) {
                    if (emailCodeLength != 0 && s.length() == emailCodeLength) {
                        buttonTextView.callOnClick();
                    }
                    showDoneButton(s.length() > 0);
                } else if (currentType == TYPE_VERIFY) {
                    if (s.length() > 0) {
                        showDoneButton(true);
                    }
                }
            }
        });
    }
    return fragmentView;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) Rect(android.graphics.Rect) ActionMode(android.view.ActionMode) LinearLayout(android.widget.LinearLayout) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) Bundle(android.os.Bundle) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AndroidUtilities(org.telegram.messenger.AndroidUtilities) Animator(android.animation.Animator) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) View(android.view.View) Canvas(android.graphics.Canvas) 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) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) ViewGroup(android.view.ViewGroup) NotificationCenter(org.telegram.messenger.NotificationCenter) UserConfig(org.telegram.messenger.UserConfig) TextView(android.widget.TextView) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) EditorInfo(android.view.inputmethod.EditorInfo) TextWatcher(android.text.TextWatcher) Typeface(android.graphics.Typeface) Context(android.content.Context) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) Theme(org.telegram.ui.ActionBar.Theme) RequestDelegate(org.telegram.tgnet.RequestDelegate) Dialog(android.app.Dialog) LocaleController(org.telegram.messenger.LocaleController) AlertsCreator(org.telegram.ui.Components.AlertsCreator) Editable(android.text.Editable) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Log(com.google.android.exoplayer2.util.Log) MotionEvent(android.view.MotionEvent) SRPHelper(org.telegram.messenger.SRPHelper) TLRPC(org.telegram.tgnet.TLRPC) Toast(android.widget.Toast) ActionBar(org.telegram.ui.ActionBar.ActionBar) Menu(android.view.Menu) TLObject(org.telegram.tgnet.TLObject) AnimatorSet(android.animation.AnimatorSet) PasswordTransformationMethod(android.text.method.PasswordTransformationMethod) Build(android.os.Build) DialogInterface(android.content.DialogInterface) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) R(org.telegram.messenger.R) TextUtils(android.text.TextUtils) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) Gravity(android.view.Gravity) TypedValue(android.util.TypedValue) ScrollView(android.widget.ScrollView) Vibrator(android.os.Vibrator) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) TLRPC(org.telegram.tgnet.TLRPC) Dialog(android.app.Dialog) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) TextView(android.widget.TextView) ImageView(android.widget.ImageView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) ActionBar(org.telegram.ui.ActionBar.ActionBar) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) Rect(android.graphics.Rect) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) RequestDelegate(org.telegram.tgnet.RequestDelegate) ActionMode(android.view.ActionMode) RLottieImageView(org.telegram.ui.Components.RLottieImageView) AnimatorSet(android.animation.AnimatorSet) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) Menu(android.view.Menu) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) ViewGroup(android.view.ViewGroup) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) View(android.view.View) RLottieImageView(org.telegram.ui.Components.RLottieImageView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) Paint(android.graphics.Paint) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ScrollView(android.widget.ScrollView) FrameLayout(android.widget.FrameLayout) LinearLayout(android.widget.LinearLayout)

Aggregations

ActionBarMenu (org.telegram.ui.ActionBar.ActionBarMenu)60 ActionBar (org.telegram.ui.ActionBar.ActionBar)52 FrameLayout (android.widget.FrameLayout)48 View (android.view.View)39 TextView (android.widget.TextView)39 TLRPC (org.telegram.tgnet.TLRPC)35 RecyclerListView (org.telegram.ui.Components.RecyclerListView)33 RecyclerView (androidx.recyclerview.widget.RecyclerView)31 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)30 AlertDialog (org.telegram.ui.ActionBar.AlertDialog)30 Paint (android.graphics.Paint)29 ActionBarMenuItem (org.telegram.ui.ActionBar.ActionBarMenuItem)28 ArrayList (java.util.ArrayList)27 Canvas (android.graphics.Canvas)25 ViewGroup (android.view.ViewGroup)25 EditTextBoldCursor (org.telegram.ui.Components.EditTextBoldCursor)25 ImageView (android.widget.ImageView)24 LinearLayout (android.widget.LinearLayout)24 BaseFragment (org.telegram.ui.ActionBar.BaseFragment)24 Animator (android.animation.Animator)23