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

Commit 16f2b90d authored by Adam Powell's avatar Adam Powell
Browse files

Show checkmarks at the start of material AlertDialog list items

Also fix a bug in parsing CheckedTextView tinting attributes

Bug 16552638

Change-Id: I20d41b6f6d418fdc115108d31f4f463e371794d2
parent e07b5955
Loading
Loading
Loading
Loading
+19 −9
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@ public class CheckedTextView extends TextView implements Checkable {

    private int mBasePadding;
    private int mCheckMarkWidth;
    private int mCheckMarkGravity = Gravity.END;

    private boolean mNeedRequestlayout;

    private static final int[] CHECKED_STATE_SET = {
@@ -83,15 +85,17 @@ public class CheckedTextView extends TextView implements Checkable {
        }

        mCheckMarkTintMode = Drawable.parseTintMode(a.getInt(
                R.styleable.CompoundButton_buttonTintMode, -1), mCheckMarkTintMode);
                R.styleable.CheckedTextView_checkMarkTintMode, -1), mCheckMarkTintMode);

        if (a.hasValue(R.styleable.CompoundButton_buttonTint)) {
            mCheckMarkTintList = a.getColorStateList(R.styleable.CompoundButton_buttonTint);
        if (a.hasValue(R.styleable.CheckedTextView_checkMarkTint)) {
            mCheckMarkTintList = a.getColorStateList(R.styleable.CheckedTextView_checkMarkTint);
            mHasCheckMarkTint = true;

            applyCheckMarkTint();
        }

        mCheckMarkGravity = a.getInt(R.styleable.CheckedTextView_checkMarkGravity, Gravity.END);

        boolean checked = a.getBoolean(R.styleable.CheckedTextView_checked, false);
        setChecked(checked);

@@ -293,7 +297,7 @@ public class CheckedTextView extends TextView implements Checkable {
    @Override
    protected void internalSetPadding(int left, int top, int right, int bottom) {
        super.internalSetPadding(left, top, right, bottom);
        setBasePadding(isLayoutRtl());
        setBasePadding(isCheckMarkAtStart());
    }

    @Override
@@ -306,7 +310,7 @@ public class CheckedTextView extends TextView implements Checkable {
        resetPaddingToInitialValues();
        int newPadding = (mCheckMarkDrawable != null) ?
                mCheckMarkWidth + mBasePadding : mBasePadding;
        if (isLayoutRtl()) {
        if (isCheckMarkAtStart()) {
            mNeedRequestlayout |= (mPaddingLeft != newPadding);
            mPaddingLeft = newPadding;
        } else {
@@ -319,14 +323,20 @@ public class CheckedTextView extends TextView implements Checkable {
        }
    }

    private void setBasePadding(boolean isLayoutRtl) {
        if (isLayoutRtl) {
    private void setBasePadding(boolean checkmarkAtStart) {
        if (checkmarkAtStart) {
            mBasePadding = mPaddingLeft;
        } else {
            mBasePadding = mPaddingRight;
        }
    }

    private boolean isCheckMarkAtStart() {
        final int gravity = Gravity.getAbsoluteGravity(mCheckMarkGravity, getLayoutDirection());
        final int hgrav = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
        return hgrav == Gravity.LEFT;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
@@ -347,13 +357,13 @@ public class CheckedTextView extends TextView implements Checkable {
                    break;
            }
            
            final boolean isLayoutRtl = isLayoutRtl();
            final boolean checkMarkAtStart = isCheckMarkAtStart();
            final int width = getWidth();
            final int top = y;
            final int bottom = top + height;
            final int left;
            final int right;
            if (isLayoutRtl) {
            if (checkMarkAtStart) {
                left = mBasePadding;
                right = left + mCheckMarkWidth;
            } else {
+1 −0
Original line number Diff line number Diff line
@@ -26,4 +26,5 @@
    android:paddingStart="16dip"
    android:paddingEnd="16dip"
    android:checkMark="?android:attr/listChoiceIndicatorMultiple"
    android:checkMarkGravity="start"
    android:ellipsize="marquee" />
+1 −0
Original line number Diff line number Diff line
@@ -26,4 +26,5 @@
    android:paddingStart="16dip"
    android:paddingEnd="16dip"
    android:checkMark="?android:attr/listChoiceIndicatorSingle"
    android:checkMarkGravity="start"
    android:ellipsize="marquee" />
+11 −0
Original line number Diff line number Diff line
@@ -3163,6 +3163,17 @@
                 result to valid color values. Saturate(S + D) -->
            <enum name="add" value="16" />
        </attr>
        <!-- Gravity for aligning a CheckedTextView's checkmark to one side or the other. -->
        <attr name="checkMarkGravity">
            <!-- Push object to the left of its container, not changing its size. -->
            <flag name="left" value="0x03" />
            <!-- Push object to the right of its container, not changing its size. -->
            <flag name="right" value="0x05" />
            <!-- Push object to the beginning of its container, not changing its size. -->
            <flag name="start" value="0x00800003" />
            <!-- Push object to the end of its container, not changing its size. -->
            <flag name="end" value="0x00800005" />
        </attr>
    </declare-styleable>
    <declare-styleable name="EditText">
    </declare-styleable>
+3 −0
Original line number Diff line number Diff line
@@ -1979,4 +1979,7 @@
  <java-symbol type="string" name="time_picker_am_label" />
  <java-symbol type="string" name="time_picker_pm_label" />
  <java-symbol type="dimen" name="text_size_small_material" />
  <java-symbol type="attr" name="checkMarkGravity" />
  <java-symbol type="layout" name="select_dialog_singlechoice_material" />
  <java-symbol type="layout" name="select_dialog_multichoice_material" />
</resources>