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

Commit 6fc225a0 authored by Fabrice Di Meglio's avatar Fabrice Di Meglio Committed by Android (Google) Code Review
Browse files

Merge "Make CheckBox / RadioButton / ToggleButton / Star widgets aware of layout direction"

parents 1f1f21aa 2842679d
Loading
Loading
Loading
Loading
+33 −6
Original line number Diff line number Diff line
@@ -224,6 +224,30 @@ public abstract class CompoundButton extends Button implements Checkable {
        info.setChecked(mChecked);
    }

    @Override
    public int getCompoundPaddingLeft() {
        int padding = super.getCompoundPaddingLeft();
        if (!isLayoutRtl()) {
            final Drawable buttonDrawable = mButtonDrawable;
            if (buttonDrawable != null) {
                padding += buttonDrawable.getIntrinsicWidth();
            }
        }
        return padding;
    }

    @Override
    public int getCompoundPaddingRight() {
        int padding = super.getCompoundPaddingRight();
        if (isLayoutRtl()) {
            final Drawable buttonDrawable = mButtonDrawable;
            if (buttonDrawable != null) {
                padding += buttonDrawable.getIntrinsicWidth();
            }
        }
        return padding;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
@@ -231,20 +255,23 @@ public abstract class CompoundButton extends Button implements Checkable {
        final Drawable buttonDrawable = mButtonDrawable;
        if (buttonDrawable != null) {
            final int verticalGravity = getGravity() & Gravity.VERTICAL_GRAVITY_MASK;
            final int height = buttonDrawable.getIntrinsicHeight();

            int y = 0;
            final int drawableHeight = buttonDrawable.getIntrinsicHeight();
            final int drawableWidth = buttonDrawable.getIntrinsicWidth();

            int top = 0;
            switch (verticalGravity) {
                case Gravity.BOTTOM:
                    y = getHeight() - height;
                    top = getHeight() - drawableHeight;
                    break;
                case Gravity.CENTER_VERTICAL:
                    y = (getHeight() - height) / 2;
                    top = (getHeight() - drawableHeight) / 2;
                    break;
            }
            int bottom = top + drawableHeight;
            int left = isLayoutRtl() ? getWidth() - drawableWidth : 0;
            int right = isLayoutRtl() ? getWidth() : drawableWidth;

            buttonDrawable.setBounds(0, y, buttonDrawable.getIntrinsicWidth(), y + height);
            buttonDrawable.setBounds(left, top, right, bottom);
            buttonDrawable.draw(canvas);
        }
    }
+0 −3
Original line number Diff line number Diff line
@@ -343,17 +343,14 @@ please see styles_device_defaults.xml.
    </style>

    <style name="Widget.CompoundButton.CheckBox">
        <item name="android:background">@android:drawable/btn_check_label_background</item>
        <item name="android:button">?android:attr/listChoiceIndicatorMultiple</item>
    </style>

    <style name="Widget.CompoundButton.RadioButton">
        <item name="android:background">@android:drawable/btn_radio_label_background</item>
        <item name="android:button">?android:attr/listChoiceIndicatorSingle</item>
    </style>

    <style name="Widget.CompoundButton.Star">
        <item name="android:background">@android:drawable/btn_star_label_background</item>
        <item name="android:button">@android:drawable/btn_star</item>
    </style>