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

Commit ddf655c4 authored by Alan Viverette's avatar Alan Viverette
Browse files

Implement RTL support in framework ViewPager, DatePicker

Lays out ViewPager in the opposite direction when in RTL mode, e.g.
the first item's starting edge is laid out at the largest possible
scrolling distance. This preserves both the meaning of positive
scrollX values and the meaning of positive adapter positions.

Also removes clickable attribute from DayPickerView since it has a
virtual view hierarchy.

Bug: 19408740
Bug: 20134073
Change-Id: Ib6f945335bd88da59c8c593c7c270e290e15d0a5
parent b5665c99
Loading
Loading
Loading
Loading
+16 −2
Original line number Original line Diff line number Diff line
@@ -195,10 +195,24 @@ class DayPickerView extends ViewGroup {
        mNextButton.measure(buttonWidthSpec, buttonHeightSpec);
        mNextButton.measure(buttonWidthSpec, buttonHeightSpec);
    }
    }


    @Override
    public void onRtlPropertiesChanged(@ResolvedLayoutDir int layoutDirection) {
        super.onRtlPropertiesChanged(layoutDirection);

        requestLayout();
    }

    @Override
    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        final ImageButton leftButton = mPrevButton;
        final ImageButton leftButton;
        final ImageButton rightButton = mNextButton;
        final ImageButton rightButton;
        if (isLayoutRtl()) {
            leftButton = mNextButton;
            rightButton = mPrevButton;
        } else {
            leftButton = mPrevButton;
            rightButton = mNextButton;
        }


        final int width = right - left;
        final int width = right - left;
        final int height = bottom - top;
        final int height = bottom - top;
+47 −9
Original line number Original line Diff line number Diff line
@@ -162,7 +162,6 @@ class SimpleMonthView extends View {
        mTitleFormatter = new SimpleDateFormat(titleFormat, locale);
        mTitleFormatter = new SimpleDateFormat(titleFormat, locale);
        mDayOfWeekFormatter = new SimpleDateFormat(DAY_OF_WEEK_FORMAT, locale);
        mDayOfWeekFormatter = new SimpleDateFormat(DAY_OF_WEEK_FORMAT, locale);


        setClickable(true);
        initPaints(res);
        initPaints(res);
    }
    }


@@ -318,7 +317,8 @@ class SimpleMonthView extends View {
        final int x = (int) (event.getX() + 0.5f);
        final int x = (int) (event.getX() + 0.5f);
        final int y = (int) (event.getY() + 0.5f);
        final int y = (int) (event.getY() + 0.5f);


        switch (event.getAction()) {
        final int action = event.getAction();
        switch (action) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_MOVE:
            case MotionEvent.ACTION_MOVE:
                final int touchedItem = getDayAtLocation(x, y);
                final int touchedItem = getDayAtLocation(x, y);
@@ -326,6 +326,10 @@ class SimpleMonthView extends View {
                    mTouchedItem = touchedItem;
                    mTouchedItem = touchedItem;
                    invalidate();
                    invalidate();
                }
                }
                if (action == MotionEvent.ACTION_DOWN && touchedItem < 0) {
                    // Touch something that's not an item, reject event.
                    return false;
                }
                break;
                break;


            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_UP:
@@ -376,9 +380,16 @@ class SimpleMonthView extends View {


        for (int col = 0; col < DAYS_IN_WEEK; col++) {
        for (int col = 0; col < DAYS_IN_WEEK; col++) {
            final int colCenter = colWidth * col + colWidth / 2;
            final int colCenter = colWidth * col + colWidth / 2;
            final int colCenterRtl;
            if (isLayoutRtl()) {
                colCenterRtl = mPaddedWidth - colCenter;
            } else {
                colCenterRtl = colCenter;
            }

            final int dayOfWeek = (col + mWeekStart) % DAYS_IN_WEEK;
            final int dayOfWeek = (col + mWeekStart) % DAYS_IN_WEEK;
            final String label = getDayOfWeekLabel(dayOfWeek);
            final String label = getDayOfWeekLabel(dayOfWeek);
            canvas.drawText(label, colCenter, rowCenter - halfLineHeight, p);
            canvas.drawText(label, colCenterRtl, rowCenter - halfLineHeight, p);
        }
        }
    }
    }


@@ -402,6 +413,13 @@ class SimpleMonthView extends View {


        for (int day = 1, col = findDayOffset(); day <= mDaysInMonth; day++) {
        for (int day = 1, col = findDayOffset(); day <= mDaysInMonth; day++) {
            final int colCenter = colWidth * col + colWidth / 2;
            final int colCenter = colWidth * col + colWidth / 2;
            final int colCenterRtl;
            if (isLayoutRtl()) {
                colCenterRtl = mPaddedWidth - colCenter;
            } else {
                colCenterRtl = colCenter;
            }

            int stateMask = 0;
            int stateMask = 0;


            if (day >= mEnabledDayStart && day <= mEnabledDayEnd) {
            if (day >= mEnabledDayStart && day <= mEnabledDayEnd) {
@@ -413,12 +431,12 @@ class SimpleMonthView extends View {
                stateMask |= StateSet.VIEW_STATE_ACTIVATED;
                stateMask |= StateSet.VIEW_STATE_ACTIVATED;


                // Adjust the circle to be centered on the row.
                // Adjust the circle to be centered on the row.
                canvas.drawCircle(colCenter, rowCenter, mDaySelectorRadius, mDaySelectorPaint);
                canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDaySelectorPaint);
            } else if (mTouchedItem == day) {
            } else if (mTouchedItem == day) {
                stateMask |= StateSet.VIEW_STATE_PRESSED;
                stateMask |= StateSet.VIEW_STATE_PRESSED;


                // Adjust the circle to be centered on the row.
                // Adjust the circle to be centered on the row.
                canvas.drawCircle(colCenter, rowCenter, mDaySelectorRadius, mDayHighlightPaint);
                canvas.drawCircle(colCenterRtl, rowCenter, mDaySelectorRadius, mDayHighlightPaint);
            }
            }


            final boolean isDayToday = mToday == day;
            final boolean isDayToday = mToday == day;
@@ -431,7 +449,7 @@ class SimpleMonthView extends View {
            }
            }
            p.setColor(dayTextColor);
            p.setColor(dayTextColor);


            canvas.drawText(Integer.toString(day), colCenter, rowCenter - halfLineHeight, p);
            canvas.drawText(Integer.toString(day), colCenterRtl, rowCenter - halfLineHeight, p);


            col++;
            col++;


@@ -582,6 +600,13 @@ class SimpleMonthView extends View {
        setMeasuredDimension(resolvedWidth, resolvedHeight);
        setMeasuredDimension(resolvedWidth, resolvedHeight);
    }
    }


    @Override
    public void onRtlPropertiesChanged(@ResolvedLayoutDir int layoutDirection) {
        super.onRtlPropertiesChanged(layoutDirection);

        requestLayout();
    }

    @Override
    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        if (!changed) {
        if (!changed) {
@@ -657,8 +682,16 @@ class SimpleMonthView extends View {
            return -1;
            return -1;
        }
        }


        // Adjust for RTL after applying padding.
        final int paddedXRtl;
        if (isLayoutRtl()) {
            paddedXRtl = mPaddedWidth - paddedX;
        } else {
            paddedXRtl = paddedX;
        }

        final int row = (paddedY - headerHeight) / mDayHeight;
        final int row = (paddedY - headerHeight) / mDayHeight;
        final int col = (paddedX * DAYS_IN_WEEK) / mPaddedWidth;
        final int col = (paddedXRtl * DAYS_IN_WEEK) / mPaddedWidth;
        final int index = col + row * DAYS_IN_WEEK;
        final int index = col + row * DAYS_IN_WEEK;
        final int day = index + 1 - findDayOffset();
        final int day = index + 1 - findDayOffset();
        if (day < 1 || day > mDaysInMonth) {
        if (day < 1 || day > mDaysInMonth) {
@@ -681,10 +714,15 @@ class SimpleMonthView extends View {


        final int index = id - 1 + findDayOffset();
        final int index = id - 1 + findDayOffset();


        // Compute left edge.
        // Compute left edge, taking into account RTL.
        final int col = index % DAYS_IN_WEEK;
        final int col = index % DAYS_IN_WEEK;
        final int colWidth = mCellWidth;
        final int colWidth = mCellWidth;
        final int left = getPaddingLeft() + col * colWidth;
        final int left;
        if (isLayoutRtl()) {
            left = getWidth() - getPaddingRight() - (col + 1) * colWidth;
        } else {
            left = getPaddingLeft() + col * colWidth;
        }


        // Compute top edge.
        // Compute top edge.
        final int row = index / DAYS_IN_WEEK;
        final int row = index / DAYS_IN_WEEK;
+279 −296

File changed.

Preview size limit exceeded, changes collapsed.

+2 −1
Original line number Original line Diff line number Diff line
@@ -18,7 +18,8 @@
        android:height="24dp"
        android:height="24dp"
        android:viewportWidth="24"
        android:viewportWidth="24"
        android:viewportHeight="24"
        android:viewportHeight="24"
        android:tint="?attr/colorControlNormal">
        android:tint="?attr/colorControlNormal"
        android:autoMirrored="true">
    <path
    <path
        android:fillColor="#FF000000"
        android:fillColor="#FF000000"
        android:pathData="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6,-6z"/>
        android:pathData="M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6,-6z"/>
+2 −1
Original line number Original line Diff line number Diff line
@@ -18,7 +18,8 @@
        android:height="24dp"
        android:height="24dp"
        android:viewportWidth="24"
        android:viewportWidth="24"
        android:viewportHeight="24"
        android:viewportHeight="24"
        android:tint="?attr/colorControlNormal">
        android:tint="?attr/colorControlNormal"
        android:autoMirrored="true">
    <path
    <path
        android:fillColor="#FF000000"
        android:fillColor="#FF000000"
        android:pathData="M15.41 7.41L14 6l-6 6 6 6 1.41,-1.41L10.83 12z"/>
        android:pathData="M15.41 7.41L14 6l-6 6 6 6 1.41,-1.41L10.83 12z"/>
Loading