Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9fc8861e authored by Olivier St-Onge's avatar Olivier St-Onge
Browse files

Check if PageIndicator's width matches the number of pages.

PageIndicator sometimes get in a state where the width isn't always updated when the number of pages change (possibly linked to if PageIndicator is visible at the time or not)
Adding this check forces a width recalculation if it doesn't match the current number of pages.

Fix: 322540792
Flag: none
Test: manually, opening QS
Change-Id: I12f584b2cd86db5a0c7e02fb88dcfaeb80893d42
parent e5b74662
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -125,7 +125,10 @@ public class PageIndicator extends ViewGroup {

    public void setNumPages(int numPages) {
        setVisibility(numPages > 1 ? View.VISIBLE : View.GONE);
        if (numPages == getChildCount()) {
        int childCount = getChildCount();
        // We're checking if the width needs to be updated as it's possible that the number of pages
        // was changed while the page indicator was not visible, automatically skipping onMeasure.
        if (numPages == childCount && calculateWidth(childCount) == getMeasuredWidth()) {
            return;
        }
        if (mAnimating) {
@@ -295,6 +298,10 @@ public class PageIndicator extends ViewGroup {
        }
    }

    private int calculateWidth(int numPages) {
        return (mPageIndicatorWidth - mPageDotWidth) * (numPages - 1) + mPageDotWidth;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        final int N = getChildCount();
@@ -309,7 +316,7 @@ public class PageIndicator extends ViewGroup {
        for (int i = 0; i < N; i++) {
            getChildAt(i).measure(widthChildSpec, heightChildSpec);
        }
        int width = (mPageIndicatorWidth - mPageDotWidth) * (N - 1) + mPageDotWidth;
        int width = calculateWidth(N);
        setMeasuredDimension(width, mPageIndicatorHeight);
    }