Search in sources :

Example 1 with LineProgressView

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

the class ArticleViewer method setParentActivity.

public void setParentActivity(Activity activity, BaseFragment fragment) {
    parentFragment = fragment;
    currentAccount = UserConfig.selectedAccount;
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingProgressDidChanged);
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidReset);
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingPlayStateChanged);
    NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.messagePlayingDidStart);
    if (parentActivity == activity) {
        updatePaintColors();
        refreshThemeColors();
        return;
    }
    parentActivity = activity;
    SharedPreferences sharedPreferences = ApplicationLoader.applicationContext.getSharedPreferences("articles", Activity.MODE_PRIVATE);
    selectedFont = sharedPreferences.getInt("font_type", 0);
    createPaint(false);
    backgroundPaint = new Paint();
    layerShadowDrawable = activity.getResources().getDrawable(R.drawable.layer_shadow);
    slideDotDrawable = activity.getResources().getDrawable(R.drawable.slide_dot_small);
    slideDotBigDrawable = activity.getResources().getDrawable(R.drawable.slide_dot_big);
    scrimPaint = new Paint();
    windowView = new WindowView(activity);
    windowView.setWillNotDraw(false);
    windowView.setClipChildren(true);
    windowView.setFocusable(false);
    containerView = new FrameLayout(activity) {

        @Override
        protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
            if (windowView.movingPage) {
                int width = getMeasuredWidth();
                int translationX = (int) listView[0].getTranslationX();
                int clipLeft = 0;
                int clipRight = width;
                if (child == listView[1]) {
                    clipRight = translationX;
                } else if (child == listView[0]) {
                    clipLeft = translationX;
                }
                final int restoreCount = canvas.save();
                canvas.clipRect(clipLeft, 0, clipRight, getHeight());
                final boolean result = super.drawChild(canvas, child, drawingTime);
                canvas.restoreToCount(restoreCount);
                if (translationX != 0) {
                    if (child == listView[0]) {
                        final float alpha = Math.max(0, Math.min((width - translationX) / (float) AndroidUtilities.dp(20), 1.0f));
                        layerShadowDrawable.setBounds(translationX - layerShadowDrawable.getIntrinsicWidth(), child.getTop(), translationX, child.getBottom());
                        layerShadowDrawable.setAlpha((int) (0xff * alpha));
                        layerShadowDrawable.draw(canvas);
                    } else if (child == listView[1]) {
                        float opacity = Math.min(0.8f, (width - translationX) / (float) width);
                        if (opacity < 0) {
                            opacity = 0;
                        }
                        scrimPaint.setColor((int) (((0x99000000 & 0xff000000) >>> 24) * opacity) << 24);
                        canvas.drawRect(clipLeft, 0, clipRight, getHeight(), scrimPaint);
                    }
                }
                return result;
            } else {
                return super.drawChild(canvas, child, drawingTime);
            }
        }
    };
    windowView.addView(containerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT));
    // containerView.setFitsSystemWindows(true);
    if (Build.VERSION.SDK_INT >= 21) {
        windowView.setFitsSystemWindows(true);
        containerView.setOnApplyWindowInsetsListener((v, insets) -> {
            if (Build.VERSION.SDK_INT >= 30) {
                return WindowInsets.CONSUMED;
            } else {
                return insets.consumeSystemWindowInsets();
            }
        });
    }
    fullscreenVideoContainer = new FrameLayout(activity);
    fullscreenVideoContainer.setBackgroundColor(0xff000000);
    fullscreenVideoContainer.setVisibility(View.INVISIBLE);
    windowView.addView(fullscreenVideoContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    fullscreenAspectRatioView = new AspectRatioFrameLayout(activity);
    fullscreenAspectRatioView.setVisibility(View.GONE);
    fullscreenVideoContainer.addView(fullscreenAspectRatioView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER));
    fullscreenTextureView = new TextureView(activity);
    listView = new RecyclerListView[2];
    adapter = new WebpageAdapter[2];
    layoutManager = new LinearLayoutManager[2];
    for (int i = 0; i < listView.length; i++) {
        WebpageAdapter webpageAdapter = adapter[i] = new WebpageAdapter(parentActivity);
        listView[i] = new RecyclerListView(activity) {

            @Override
            protected void onLayout(boolean changed, int l, int t, int r, int b) {
                super.onLayout(changed, l, t, r, b);
                int count = getChildCount();
                for (int a = 0; a < count; a++) {
                    View child = getChildAt(a);
                    if (child.getTag() instanceof Integer) {
                        Integer tag = (Integer) child.getTag();
                        if (tag == 90) {
                            int bottom = child.getBottom();
                            if (bottom < getMeasuredHeight()) {
                                int height = getMeasuredHeight();
                                child.layout(0, height - child.getMeasuredHeight(), child.getMeasuredWidth(), height);
                                break;
                            }
                        }
                    }
                }
            }

            @Override
            public boolean onInterceptTouchEvent(MotionEvent e) {
                if (pressedLinkOwnerLayout != null && pressedLink == null && (popupWindow == null || !popupWindow.isShowing()) && (e.getAction() == MotionEvent.ACTION_UP || e.getAction() == MotionEvent.ACTION_CANCEL)) {
                    pressedLink = null;
                    pressedLinkOwnerLayout = null;
                    pressedLinkOwnerView = null;
                } else if (pressedLinkOwnerLayout != null && pressedLink != null && e.getAction() == MotionEvent.ACTION_UP) {
                    checkLayoutForLinks(webpageAdapter, e, pressedLinkOwnerView, pressedLinkOwnerLayout, 0, 0);
                }
                return super.onInterceptTouchEvent(e);
            }

            @Override
            public boolean onTouchEvent(MotionEvent e) {
                if (pressedLinkOwnerLayout != null && pressedLink == null && (popupWindow == null || !popupWindow.isShowing()) && (e.getAction() == MotionEvent.ACTION_UP || e.getAction() == MotionEvent.ACTION_CANCEL)) {
                    pressedLink = null;
                    pressedLinkOwnerLayout = null;
                    pressedLinkOwnerView = null;
                }
                return super.onTouchEvent(e);
            }

            @Override
            public void setTranslationX(float translationX) {
                super.setTranslationX(translationX);
                if (windowView.movingPage) {
                    containerView.invalidate();
                    float progress = translationX / getMeasuredWidth();
                    setCurrentHeaderHeight((int) (windowView.startMovingHeaderHeight + (AndroidUtilities.dp(56) - windowView.startMovingHeaderHeight) * progress));
                }
            }
        };
        ((DefaultItemAnimator) listView[i].getItemAnimator()).setDelayAnimations(false);
        listView[i].setLayoutManager(layoutManager[i] = new LinearLayoutManager(parentActivity, LinearLayoutManager.VERTICAL, false));
        listView[i].setAdapter(webpageAdapter);
        listView[i].setClipToPadding(false);
        listView[i].setVisibility(i == 0 ? View.VISIBLE : View.GONE);
        listView[i].setPadding(0, AndroidUtilities.dp(56), 0, 0);
        listView[i].setTopGlowOffset(AndroidUtilities.dp(56));
        containerView.addView(listView[i], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
        listView[i].setOnItemLongClickListener((view, position) -> {
            if (view instanceof BlockRelatedArticlesCell) {
                BlockRelatedArticlesCell cell = (BlockRelatedArticlesCell) view;
                showCopyPopup(cell.currentBlock.parent.articles.get(cell.currentBlock.num).url);
                return true;
            }
            return false;
        });
        listView[i].setOnItemClickListener((view, position, x, y) -> {
            if (textSelectionHelper != null) {
                if (textSelectionHelper.isSelectionMode()) {
                    textSelectionHelper.clear();
                    return;
                }
                textSelectionHelper.clear();
            }
            if (view instanceof ReportCell && webpageAdapter.currentPage != null) {
                ReportCell cell = (ReportCell) view;
                if (previewsReqId != 0 || cell.hasViews && x < view.getMeasuredWidth() / 2) {
                    return;
                }
                TLObject object = MessagesController.getInstance(currentAccount).getUserOrChat("previews");
                if (object instanceof TLRPC.TL_user) {
                    openPreviewsChat((TLRPC.User) object, webpageAdapter.currentPage.id);
                } else {
                    final int currentAccount = UserConfig.selectedAccount;
                    final long pageId = webpageAdapter.currentPage.id;
                    showProgressView(true, true);
                    TLRPC.TL_contacts_resolveUsername req = new TLRPC.TL_contacts_resolveUsername();
                    req.username = "previews";
                    previewsReqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                        if (previewsReqId == 0) {
                            return;
                        }
                        previewsReqId = 0;
                        showProgressView(true, false);
                        if (response != null) {
                            TLRPC.TL_contacts_resolvedPeer res = (TLRPC.TL_contacts_resolvedPeer) response;
                            MessagesController.getInstance(currentAccount).putUsers(res.users, false);
                            MessagesStorage.getInstance(currentAccount).putUsersAndChats(res.users, res.chats, false, true);
                            if (!res.users.isEmpty()) {
                                openPreviewsChat(res.users.get(0), pageId);
                            }
                        }
                    }));
                }
            } else if (position >= 0 && position < webpageAdapter.localBlocks.size()) {
                TLRPC.PageBlock pageBlock = webpageAdapter.localBlocks.get(position);
                TLRPC.PageBlock originalBlock = pageBlock;
                pageBlock = getLastNonListPageBlock(pageBlock);
                if (pageBlock instanceof TL_pageBlockDetailsChild) {
                    TL_pageBlockDetailsChild detailsChild = (TL_pageBlockDetailsChild) pageBlock;
                    pageBlock = detailsChild.block;
                }
                if (pageBlock instanceof TLRPC.TL_pageBlockChannel) {
                    TLRPC.TL_pageBlockChannel pageBlockChannel = (TLRPC.TL_pageBlockChannel) pageBlock;
                    MessagesController.getInstance(currentAccount).openByUserName(pageBlockChannel.channel.username, parentFragment, 2);
                    close(false, true);
                } else if (pageBlock instanceof TL_pageBlockRelatedArticlesChild) {
                    TL_pageBlockRelatedArticlesChild pageBlockRelatedArticlesChild = (TL_pageBlockRelatedArticlesChild) pageBlock;
                    openWebpageUrl(pageBlockRelatedArticlesChild.parent.articles.get(pageBlockRelatedArticlesChild.num).url, null);
                } else if (pageBlock instanceof TLRPC.TL_pageBlockDetails) {
                    view = getLastNonListCell(view);
                    if (!(view instanceof BlockDetailsCell)) {
                        return;
                    }
                    pressedLinkOwnerLayout = null;
                    pressedLinkOwnerView = null;
                    int index = webpageAdapter.blocks.indexOf(originalBlock);
                    if (index < 0) {
                        return;
                    }
                    TLRPC.TL_pageBlockDetails pageBlockDetails = (TLRPC.TL_pageBlockDetails) pageBlock;
                    pageBlockDetails.open = !pageBlockDetails.open;
                    int oldCount = webpageAdapter.getItemCount();
                    webpageAdapter.updateRows();
                    int newCount = webpageAdapter.getItemCount();
                    int changeCount = Math.abs(newCount - oldCount);
                    BlockDetailsCell cell = (BlockDetailsCell) view;
                    cell.arrow.setAnimationProgressAnimated(pageBlockDetails.open ? 0.0f : 1.0f);
                    cell.invalidate();
                    if (changeCount != 0) {
                        if (pageBlockDetails.open) {
                            webpageAdapter.notifyItemRangeInserted(position + 1, changeCount);
                        } else {
                            webpageAdapter.notifyItemRangeRemoved(position + 1, changeCount);
                        }
                    }
                }
            }
        });
        listView[i].setOnScrollListener(new RecyclerView.OnScrollListener() {

            @Override
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                    textSelectionHelper.stopScrolling();
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                if (recyclerView.getChildCount() == 0) {
                    return;
                }
                textSelectionHelper.onParentScrolled();
                headerView.invalidate();
                checkScroll(dy);
            }
        });
    }
    headerPaint.setColor(0xff000000);
    statusBarPaint.setColor(0xff000000);
    headerProgressPaint.setColor(0xff242426);
    headerView = new FrameLayout(activity) {

        @Override
        protected void onDraw(Canvas canvas) {
            int width = getMeasuredWidth();
            int height = getMeasuredHeight();
            canvas.drawRect(0, 0, width, height, headerPaint);
            if (layoutManager == null) {
                return;
            }
            int first = layoutManager[0].findFirstVisibleItemPosition();
            int last = layoutManager[0].findLastVisibleItemPosition();
            int count = layoutManager[0].getItemCount();
            View view;
            if (last >= count - 2) {
                view = layoutManager[0].findViewByPosition(count - 2);
            } else {
                view = layoutManager[0].findViewByPosition(first);
            }
            if (view == null) {
                return;
            }
            float itemProgress = width / (float) (count - 1);
            int childCount = layoutManager[0].getChildCount();
            float viewHeight = view.getMeasuredHeight();
            float viewProgress;
            if (last >= count - 2) {
                viewProgress = (count - 2 - first) * itemProgress * (listView[0].getMeasuredHeight() - view.getTop()) / viewHeight;
            } else {
                viewProgress = itemProgress * (1.0f - (Math.min(0, view.getTop() - listView[0].getPaddingTop()) + viewHeight) / viewHeight);
            }
            float progress = first * itemProgress + viewProgress;
            canvas.drawRect(0, 0, progress, height, headerProgressPaint);
        }
    };
    headerView.setWillNotDraw(false);
    containerView.addView(headerView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 56));
    headerView.setOnClickListener(v -> listView[0].smoothScrollToPosition(0));
    titleTextView = new SimpleTextView(activity);
    titleTextView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
    titleTextView.setTextSize(20);
    titleTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    titleTextView.setTextColor(0xffb3b3b3);
    titleTextView.setPivotX(0.0f);
    titleTextView.setPivotY(AndroidUtilities.dp(28));
    headerView.addView(titleTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 56, Gravity.LEFT | Gravity.TOP, 72, 0, 48 * 2, 0));
    lineProgressView = new LineProgressView(activity);
    lineProgressView.setProgressColor(0xffffffff);
    lineProgressView.setPivotX(0.0f);
    lineProgressView.setPivotY(AndroidUtilities.dp(2));
    headerView.addView(lineProgressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 2, Gravity.LEFT | Gravity.BOTTOM, 0, 0, 0, 1));
    lineProgressTickRunnable = () -> {
        float progressLeft = 0.7f - lineProgressView.getCurrentProgress();
        if (progressLeft > 0.0f) {
            float tick;
            if (progressLeft < 0.25f) {
                tick = 0.01f;
            } else {
                tick = 0.02f;
            }
            lineProgressView.setProgress(lineProgressView.getCurrentProgress() + tick, true);
            AndroidUtilities.runOnUIThread(lineProgressTickRunnable, 100);
        }
    };
    menuContainer = new FrameLayout(activity);
    headerView.addView(menuContainer, LayoutHelper.createFrame(48, 56, Gravity.TOP | Gravity.RIGHT));
    searchShadow = new View(activity);
    searchShadow.setBackgroundResource(R.drawable.header_shadow);
    searchShadow.setAlpha(0.0f);
    containerView.addView(searchShadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.LEFT | Gravity.TOP, 0, 56, 0, 0));
    searchContainer = new FrameLayout(parentActivity);
    searchContainer.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    searchContainer.setVisibility(View.INVISIBLE);
    if (Build.VERSION.SDK_INT < 21) {
        searchContainer.setAlpha(0.0f);
    }
    headerView.addView(searchContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 56));
    searchField = new EditTextBoldCursor(parentActivity) {

        @Override
        public boolean onTouchEvent(MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                if (!AndroidUtilities.showKeyboard(this)) {
                    clearFocus();
                    requestFocus();
                }
            }
            return super.onTouchEvent(event);
        }
    };
    searchField.setCursorWidth(1.5f);
    searchField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    searchField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    searchField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    searchField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
    searchField.setSingleLine(true);
    searchField.setHint(LocaleController.getString("Search", R.string.Search));
    searchField.setBackgroundResource(0);
    searchField.setPadding(0, 0, 0, 0);
    int inputType = searchField.getInputType() | EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
    searchField.setInputType(inputType);
    if (Build.VERSION.SDK_INT < 23) {
        searchField.setCustomSelectionActionModeCallback(new ActionMode.Callback() {

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

            public void onDestroyActionMode(ActionMode mode) {
            }

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

            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                return false;
            }
        });
    }
    searchField.setOnEditorActionListener((v, actionId, event) -> {
        if (event != null && (event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_SEARCH || event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
            AndroidUtilities.hideKeyboard(searchField);
        }
        return false;
    });
    searchField.addTextChangedListener(new TextWatcher() {

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

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (ignoreOnTextChange) {
                ignoreOnTextChange = false;
                return;
            }
            processSearch(s.toString().toLowerCase());
            if (clearButton != null) {
                if (TextUtils.isEmpty(s)) {
                    if (clearButton.getTag() != null) {
                        clearButton.setTag(null);
                        clearButton.clearAnimation();
                        if (animateClear) {
                            clearButton.animate().setInterpolator(new DecelerateInterpolator()).alpha(0.0f).setDuration(180).scaleY(0.0f).scaleX(0.0f).rotation(45).withEndAction(() -> clearButton.setVisibility(View.INVISIBLE)).start();
                        } else {
                            clearButton.setAlpha(0.0f);
                            clearButton.setRotation(45);
                            clearButton.setScaleX(0.0f);
                            clearButton.setScaleY(0.0f);
                            clearButton.setVisibility(View.INVISIBLE);
                            animateClear = true;
                        }
                    }
                } else {
                    if (clearButton.getTag() == null) {
                        clearButton.setTag(1);
                        clearButton.clearAnimation();
                        clearButton.setVisibility(View.VISIBLE);
                        if (animateClear) {
                            clearButton.animate().setInterpolator(new DecelerateInterpolator()).alpha(1.0f).setDuration(180).scaleY(1.0f).scaleX(1.0f).rotation(0).start();
                        } else {
                            clearButton.setAlpha(1.0f);
                            clearButton.setRotation(0);
                            clearButton.setScaleX(1.0f);
                            clearButton.setScaleY(1.0f);
                            animateClear = true;
                        }
                    }
                }
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
    searchField.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN | EditorInfo.IME_ACTION_SEARCH);
    searchField.setTextIsSelectable(false);
    searchContainer.addView(searchField, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 36, Gravity.CENTER_VERTICAL, 72, 0, 48, 0));
    clearButton = new ImageView(parentActivity) {

        @Override
        protected void onDetachedFromWindow() {
            super.onDetachedFromWindow();
            clearAnimation();
            if (getTag() == null) {
                clearButton.setVisibility(INVISIBLE);
                clearButton.setAlpha(0.0f);
                clearButton.setRotation(45);
                clearButton.setScaleX(0.0f);
                clearButton.setScaleY(0.0f);
            } else {
                clearButton.setAlpha(1.0f);
                clearButton.setRotation(0);
                clearButton.setScaleX(1.0f);
                clearButton.setScaleY(1.0f);
            }
        }
    };
    clearButton.setImageDrawable(new CloseProgressDrawable2());
    clearButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText), PorterDuff.Mode.MULTIPLY));
    clearButton.setScaleType(ImageView.ScaleType.CENTER);
    clearButton.setAlpha(0.0f);
    clearButton.setRotation(45);
    clearButton.setScaleX(0.0f);
    clearButton.setScaleY(0.0f);
    clearButton.setOnClickListener(v -> {
        if (searchField.length() != 0) {
            searchField.setText("");
        }
        searchField.requestFocus();
        AndroidUtilities.showKeyboard(searchField);
    });
    clearButton.setContentDescription(LocaleController.getString("ClearButton", R.string.ClearButton));
    searchContainer.addView(clearButton, LayoutHelper.createFrame(48, LayoutHelper.MATCH_PARENT, Gravity.CENTER_VERTICAL | Gravity.RIGHT));
    backButton = new ImageView(activity);
    backButton.setScaleType(ImageView.ScaleType.CENTER);
    backDrawable = new BackDrawable(false);
    backDrawable.setAnimationTime(200.0f);
    backDrawable.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    backDrawable.setRotatedColor(0xffb3b3b3);
    backDrawable.setRotation(1.0f, false);
    backButton.setImageDrawable(backDrawable);
    backButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
    headerView.addView(backButton, LayoutHelper.createFrame(54, 56));
    backButton.setOnClickListener(v -> {
        /*if (collapsed) {
                uncollapse();
            } else {
                collapse();
            }*/
        if (searchContainer.getTag() != null) {
            showSearch(false);
        } else {
            close(true, true);
        }
    });
    backButton.setContentDescription(LocaleController.getString("AccDescrGoBack", R.string.AccDescrGoBack));
    menuButton = new ActionBarMenuItem(parentActivity, null, Theme.ACTION_BAR_WHITE_SELECTOR_COLOR, 0xffb3b3b3) {

        @Override
        public void toggleSubMenu() {
            super.toggleSubMenu();
            listView[0].stopScroll();
            checkScrollAnimated();
        }
    };
    menuButton.setLayoutInScreen(true);
    menuButton.setDuplicateParentStateEnabled(false);
    menuButton.setClickable(true);
    menuButton.setIcon(R.drawable.ic_ab_other);
    menuButton.addSubItem(search_item, R.drawable.msg_search, LocaleController.getString("Search", R.string.Search));
    menuButton.addSubItem(share_item, R.drawable.msg_share, LocaleController.getString("ShareFile", R.string.ShareFile));
    menuButton.addSubItem(open_item, R.drawable.msg_openin, LocaleController.getString("OpenInExternalApp", R.string.OpenInExternalApp));
    menuButton.addSubItem(settings_item, R.drawable.menu_settings, LocaleController.getString("Settings", R.string.Settings));
    menuButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.ACTION_BAR_WHITE_SELECTOR_COLOR));
    menuButton.setContentDescription(LocaleController.getString("AccDescrMoreOptions", R.string.AccDescrMoreOptions));
    menuContainer.addView(menuButton, LayoutHelper.createFrame(48, 56));
    progressView = new ContextProgressView(activity, 2);
    progressView.setVisibility(View.GONE);
    menuContainer.addView(progressView, LayoutHelper.createFrame(48, 56));
    menuButton.setOnClickListener(v -> menuButton.toggleSubMenu());
    menuButton.setDelegate(id -> {
        if (adapter[0].currentPage == null || parentActivity == null) {
            return;
        }
        if (id == search_item) {
            showSearch(true);
        } else if (id == share_item) {
            showDialog(new ShareAlert(parentActivity, null, adapter[0].currentPage.url, false, adapter[0].currentPage.url, false));
        } else if (id == open_item) {
            String webPageUrl;
            if (!TextUtils.isEmpty(adapter[0].currentPage.cached_page.url)) {
                webPageUrl = adapter[0].currentPage.cached_page.url;
            } else {
                webPageUrl = adapter[0].currentPage.url;
            }
            Browser.openUrl(parentActivity, webPageUrl, true, false);
        } else if (id == settings_item) {
            BottomSheet.Builder builder = new BottomSheet.Builder(parentActivity);
            builder.setApplyTopPadding(false);
            LinearLayout settingsContainer = new LinearLayout(parentActivity);
            settingsContainer.setPadding(0, 0, 0, AndroidUtilities.dp(4));
            settingsContainer.setOrientation(LinearLayout.VERTICAL);
            HeaderCell headerCell = new HeaderCell(parentActivity);
            headerCell.setText(LocaleController.getString("FontSize", R.string.FontSize));
            settingsContainer.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 3, 1, 3, 0));
            TextSizeCell sizeCell = new TextSizeCell(parentActivity);
            settingsContainer.addView(sizeCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 3, 0, 3, 0));
            headerCell = new HeaderCell(parentActivity);
            headerCell.setText(LocaleController.getString("FontType", R.string.FontType));
            settingsContainer.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 3, 4, 3, 2));
            for (int a = 0; a < 2; a++) {
                fontCells[a] = new FontCell(parentActivity);
                switch(a) {
                    case 0:
                        fontCells[a].setTextAndTypeface(LocaleController.getString("Default", R.string.Default), Typeface.DEFAULT);
                        break;
                    case 1:
                        fontCells[a].setTextAndTypeface("Serif", Typeface.SERIF);
                        break;
                }
                fontCells[a].select(a == selectedFont, false);
                fontCells[a].setTag(a);
                fontCells[a].setOnClickListener(v -> {
                    int num = (Integer) v.getTag();
                    selectedFont = num;
                    for (int a1 = 0; a1 < 2; a1++) {
                        fontCells[a1].select(a1 == num, true);
                    }
                    updatePaintFonts();
                    for (int i = 0; i < listView.length; i++) {
                        adapter[i].notifyDataSetChanged();
                    }
                });
                settingsContainer.addView(fontCells[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
            }
            builder.setCustomView(settingsContainer);
            showDialog(linkSheet = builder.create());
        }
    });
    searchPanel = new FrameLayout(parentActivity) {

        @Override
        public void onDraw(Canvas canvas) {
            int bottom = Theme.chat_composeShadowDrawable.getIntrinsicHeight();
            Theme.chat_composeShadowDrawable.setBounds(0, 0, getMeasuredWidth(), bottom);
            Theme.chat_composeShadowDrawable.draw(canvas);
            canvas.drawRect(0, bottom, getMeasuredWidth(), getMeasuredHeight(), Theme.chat_composeBackgroundPaint);
        }
    };
    searchPanel.setOnTouchListener((v, event) -> true);
    searchPanel.setWillNotDraw(false);
    searchPanel.setVisibility(View.INVISIBLE);
    searchPanel.setFocusable(true);
    searchPanel.setFocusableInTouchMode(true);
    searchPanel.setClickable(true);
    searchPanel.setPadding(0, AndroidUtilities.dp(3), 0, 0);
    containerView.addView(searchPanel, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 51, Gravity.BOTTOM));
    searchUpButton = new ImageView(parentActivity);
    searchUpButton.setScaleType(ImageView.ScaleType.CENTER);
    searchUpButton.setImageResource(R.drawable.msg_go_up);
    searchUpButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText), PorterDuff.Mode.MULTIPLY));
    searchUpButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.getColor(Theme.key_actionBarActionModeDefaultSelector), 1));
    searchPanel.addView(searchUpButton, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP, 0, 0, 48, 0));
    searchUpButton.setOnClickListener(view -> scrollToSearchIndex(currentSearchIndex - 1));
    searchUpButton.setContentDescription(LocaleController.getString("AccDescrSearchNext", R.string.AccDescrSearchNext));
    searchDownButton = new ImageView(parentActivity);
    searchDownButton.setScaleType(ImageView.ScaleType.CENTER);
    searchDownButton.setImageResource(R.drawable.msg_go_down);
    searchDownButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText), PorterDuff.Mode.MULTIPLY));
    searchDownButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.getColor(Theme.key_actionBarActionModeDefaultSelector), 1));
    searchPanel.addView(searchDownButton, LayoutHelper.createFrame(48, 48, Gravity.RIGHT | Gravity.TOP, 0, 0, 0, 0));
    searchDownButton.setOnClickListener(view -> scrollToSearchIndex(currentSearchIndex + 1));
    searchDownButton.setContentDescription(LocaleController.getString("AccDescrSearchPrev", R.string.AccDescrSearchPrev));
    searchCountText = new SimpleTextView(parentActivity);
    searchCountText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    searchCountText.setTextSize(15);
    searchCountText.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    searchCountText.setGravity(Gravity.LEFT);
    searchPanel.addView(searchCountText, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.CENTER_VERTICAL, 18, 0, 108, 0));
    windowLayoutParams = new WindowManager.LayoutParams();
    windowLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT;
    windowLayoutParams.format = PixelFormat.TRANSLUCENT;
    windowLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
    windowLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    windowLayoutParams.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW - 1;
    windowLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
    windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
    if (Build.VERSION.SDK_INT >= 21) {
        windowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
        if (Build.VERSION.SDK_INT >= 28) {
            windowLayoutParams.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
        }
    }
    textSelectionHelper = new TextSelectionHelper.ArticleTextSelectionHelper();
    textSelectionHelper.setParentView(listView[0]);
    if (MessagesController.getGlobalMainSettings().getBoolean("translate_button", false)) {
        textSelectionHelper.setOnTranslate((text, fromLang, toLang, onAlertDismiss) -> {
            TranslateAlert.showAlert(parentActivity, parentFragment, fromLang, toLang, text, false, null, onAlertDismiss);
        });
    }
    textSelectionHelper.layoutManager = layoutManager[0];
    textSelectionHelper.setCallback(new TextSelectionHelper.Callback() {

        @Override
        public void onStateChanged(boolean isSelected) {
            if (isSelected) {
                showSearch(false);
            }
        }

        @Override
        public void onTextCopied() {
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
                BulletinFactory.of(containerView, null).createCopyBulletin(LocaleController.getString("TextCopied", R.string.TextCopied)).show();
            }
        }
    });
    containerView.addView(textSelectionHelper.getOverlayView(activity));
    pinchToZoomHelper = new PinchToZoomHelper(containerView, windowView);
    pinchToZoomHelper.setClipBoundsListener(new PinchToZoomHelper.ClipBoundsListener() {

        @Override
        public void getClipTopBottom(float[] topBottom) {
            topBottom[0] = currentHeaderHeight;
            topBottom[1] = listView[0].getMeasuredHeight();
        }
    });
    pinchToZoomHelper.setCallback(new PinchToZoomHelper.Callback() {

        @Override
        public void onZoomStarted(MessageObject messageObject) {
            if (listView[0] != null) {
                listView[0].cancelClickRunnables(true);
            }
        }
    });
    updatePaintColors();
}
Also used : POSITION_FLAG_RIGHT(org.telegram.messenger.MessageObject.POSITION_FLAG_RIGHT) JavascriptInterface(android.webkit.JavascriptInterface) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) ColorDrawable(android.graphics.drawable.ColorDrawable) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) Drawable(android.graphics.drawable.Drawable) Property(android.util.Property) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) MediaActionDrawable(org.telegram.ui.Components.MediaActionDrawable) HorizontalScrollView(android.widget.HorizontalScrollView) Keep(androidx.annotation.Keep) CookieManager(android.webkit.CookieManager) RadioButton(org.telegram.ui.Components.RadioButton) Canvas(android.graphics.Canvas) TargetApi(android.annotation.TargetApi) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) AnimationProperties(org.telegram.ui.Components.AnimationProperties) MetricAffectingSpan(android.text.style.MetricAffectingSpan) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) NotificationCenter(org.telegram.messenger.NotificationCenter) TextPaintSpan(org.telegram.ui.Components.TextPaintSpan) HapticFeedbackConstants(android.view.HapticFeedbackConstants) StaticLayoutEx(org.telegram.ui.Components.StaticLayoutEx) Layout(android.text.Layout) TextPaint(android.text.TextPaint) TextPaintMarkSpan(org.telegram.ui.Components.TextPaintMarkSpan) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TextWatcher(android.text.TextWatcher) FileLoader(org.telegram.messenger.FileLoader) ViewPager(androidx.viewpager.widget.ViewPager) Dialog(android.app.Dialog) AlertsCreator(org.telegram.ui.Components.AlertsCreator) Editable(android.text.Editable) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) DisplayCutout(android.view.DisplayCutout) WebSettings(android.webkit.WebSettings) TLRPC(org.telegram.tgnet.TLRPC) Toast(android.widget.Toast) Menu(android.view.Menu) WebChromeClient(android.webkit.WebChromeClient) AspectRatioFrameLayout(com.google.android.exoplayer2.ui.AspectRatioFrameLayout) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) URLSpan(android.text.style.URLSpan) R(org.telegram.messenger.R) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) TextUtils(android.text.TextUtils) POSITION_FLAG_TOP(org.telegram.messenger.MessageObject.POSITION_FLAG_TOP) File(java.io.File) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) MessagesStorage(org.telegram.messenger.MessagesStorage) ValueAnimator(android.animation.ValueAnimator) Rect(android.graphics.Rect) ActionMode(android.view.ActionMode) LinearLayout(android.widget.LinearLayout) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) AnimatedArrowDrawable(org.telegram.ui.Components.AnimatedArrowDrawable) RadialProgress2(org.telegram.ui.Components.RadialProgress2) URLDecoder(java.net.URLDecoder) Spannable(android.text.Spannable) WindowManager(android.view.WindowManager) AndroidUtilities(org.telegram.messenger.AndroidUtilities) CubicBezierInterpolator(org.telegram.ui.Components.CubicBezierInterpolator) Animator(android.animation.Animator) POSITION_FLAG_BOTTOM(org.telegram.messenger.MessageObject.POSITION_FLAG_BOTTOM) TypefaceSpan(org.telegram.ui.Components.TypefaceSpan) WebFile(org.telegram.messenger.WebFile) ViewConfiguration(android.view.ViewConfiguration) JSONObject(org.json.JSONObject) ApplicationLoader(org.telegram.messenger.ApplicationLoader) Locale(java.util.Locale) WebViewClient(android.webkit.WebViewClient) MediaController(org.telegram.messenger.MediaController) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) WebView(android.webkit.WebView) DataSetObserver(android.database.DataSetObserver) POSITION_FLAG_LEFT(org.telegram.messenger.MessageObject.POSITION_FLAG_LEFT) RectF(android.graphics.RectF) ImageLoader(org.telegram.messenger.ImageLoader) IntEvaluator(android.animation.IntEvaluator) ContextProgressView(org.telegram.ui.Components.ContextProgressView) Utilities(org.telegram.messenger.Utilities) ObjectAnimator(android.animation.ObjectAnimator) GridLayoutManagerFixed(androidx.recyclerview.widget.GridLayoutManagerFixed) ImageLocation(org.telegram.messenger.ImageLocation) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) ViewAnimationUtils(android.view.ViewAnimationUtils) TextPaintImageReceiverSpan(org.telegram.ui.Components.TextPaintImageReceiverSpan) PorterDuff(android.graphics.PorterDuff) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) BackDrawable(org.telegram.ui.ActionBar.BackDrawable) TableLayout(org.telegram.ui.Components.TableLayout) ViewGroup(android.view.ViewGroup) ShareAlert(org.telegram.ui.Components.ShareAlert) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) SparseArray(android.util.SparseArray) UserConfig(org.telegram.messenger.UserConfig) List(java.util.List) TextView(android.widget.TextView) WebPlayerView(org.telegram.ui.Components.WebPlayerView) WindowInsets(android.view.WindowInsets) LinkPath(org.telegram.ui.Components.LinkPath) EditorInfo(android.view.inputmethod.EditorInfo) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ActionBarPopupWindow(org.telegram.ui.ActionBar.ActionBarPopupWindow) Typeface(android.graphics.Typeface) Context(android.content.Context) StaticLayout(android.text.StaticLayout) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) TextSelectionHelper(org.telegram.ui.Cells.TextSelectionHelper) Spanned(android.text.Spanned) KeyEvent(android.view.KeyEvent) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) Theme(org.telegram.ui.ActionBar.Theme) TextPaintWebpageUrlSpan(org.telegram.ui.Components.TextPaintWebpageUrlSpan) PagerAdapter(androidx.viewpager.widget.PagerAdapter) BulletinFactory(org.telegram.ui.Components.BulletinFactory) TextPaintUrlSpan(org.telegram.ui.Components.TextPaintUrlSpan) Intent(android.content.Intent) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) HeaderCell(org.telegram.ui.Cells.HeaderCell) TranslateAlert(org.telegram.ui.Components.TranslateAlert) PixelFormat(android.graphics.PixelFormat) MenuItem(android.view.MenuItem) SeekBar(org.telegram.ui.Components.SeekBar) VelocityTracker(android.view.VelocityTracker) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) ActionBar(org.telegram.ui.ActionBar.ActionBar) TLObject(org.telegram.tgnet.TLObject) AnimatorSet(android.animation.AnimatorSet) MessageObject(org.telegram.messenger.MessageObject) SharedConfig(org.telegram.messenger.SharedConfig) Build(android.os.Build) AnchorSpan(org.telegram.ui.Components.AnchorSpan) SeekBarView(org.telegram.ui.Components.SeekBarView) DownloadController(org.telegram.messenger.DownloadController) Browser(org.telegram.messenger.browser.Browser) LongSparseArray(androidx.collection.LongSparseArray) LayoutHelper(org.telegram.ui.Components.LayoutHelper) TextureView(android.view.TextureView) FileLog(org.telegram.messenger.FileLog) LineProgressView(org.telegram.ui.Components.LineProgressView) MessagesController(org.telegram.messenger.MessagesController) Color(android.graphics.Color) SoundEffectConstants(android.view.SoundEffectConstants) CloseProgressDrawable2(org.telegram.ui.Components.CloseProgressDrawable2) Activity(android.app.Activity) ImageReceiver(org.telegram.messenger.ImageReceiver) Collections(java.util.Collections) RecyclerListView(org.telegram.ui.Components.RecyclerListView) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) SpannableStringBuilder(android.text.SpannableStringBuilder) HeaderCell(org.telegram.ui.Cells.HeaderCell) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) CloseProgressDrawable2(org.telegram.ui.Components.CloseProgressDrawable2) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) TLRPC(org.telegram.tgnet.TLRPC) ImageView(android.widget.ImageView) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) Canvas(android.graphics.Canvas) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) ActionMode(android.view.ActionMode) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) ContextProgressView(org.telegram.ui.Components.ContextProgressView) ShareAlert(org.telegram.ui.Components.ShareAlert) BackDrawable(org.telegram.ui.ActionBar.BackDrawable) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) RecyclerListView(org.telegram.ui.Components.RecyclerListView) WindowManager(android.view.WindowManager) AspectRatioFrameLayout(com.google.android.exoplayer2.ui.AspectRatioFrameLayout) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextureView(android.view.TextureView) Menu(android.view.Menu) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) SharedPreferences(android.content.SharedPreferences) TextSelectionHelper(org.telegram.ui.Cells.TextSelectionHelper) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) WebView(android.webkit.WebView) ContextProgressView(org.telegram.ui.Components.ContextProgressView) TextView(android.widget.TextView) WebPlayerView(org.telegram.ui.Components.WebPlayerView) SeekBarView(org.telegram.ui.Components.SeekBarView) TextureView(android.view.TextureView) LineProgressView(org.telegram.ui.Components.LineProgressView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) TLObject(org.telegram.tgnet.TLObject) FrameLayout(android.widget.FrameLayout) AspectRatioFrameLayout(com.google.android.exoplayer2.ui.AspectRatioFrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView) LineProgressView(org.telegram.ui.Components.LineProgressView) MessageObject(org.telegram.messenger.MessageObject) LinearLayout(android.widget.LinearLayout)

Example 2 with LineProgressView

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

the class ThemeDescription method setColor.

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

Example 3 with LineProgressView

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

the class ThemeDescription method processViewColor.

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

Example 4 with LineProgressView

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

the class AlertDialog method onCreate.

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

        private boolean inLayout;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Aggregations

PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)4 TextPaint (android.text.TextPaint)4 Paint (android.graphics.Paint)3 ColorDrawable (android.graphics.drawable.ColorDrawable)3 Drawable (android.graphics.drawable.Drawable)3 View (android.view.View)3 ImageView (android.widget.ImageView)3 ScrollView (android.widget.ScrollView)3 TextView (android.widget.TextView)3 LineProgressView (org.telegram.ui.Components.LineProgressView)3 RLottieImageView (org.telegram.ui.Components.RLottieImageView)3 RadialProgressView (org.telegram.ui.Components.RadialProgressView)3 Canvas (android.graphics.Canvas)2 Rect (android.graphics.Rect)2 GradientDrawable (android.graphics.drawable.GradientDrawable)2 RippleDrawable (android.graphics.drawable.RippleDrawable)2 ShapeDrawable (android.graphics.drawable.ShapeDrawable)2 StateListDrawable (android.graphics.drawable.StateListDrawable)2 ViewGroup (android.view.ViewGroup)2 AnimatedArrowDrawable (org.telegram.ui.Components.AnimatedArrowDrawable)2