Skip to content

Commit

Permalink
[M3][Card] Change checkedIconGravity values to enum
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 408415041
  • Loading branch information
drchen committed Nov 10, 2021
1 parent 9b5356f commit bc56d5b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
Expand Up @@ -30,6 +30,7 @@
import androidx.appcompat.content.res.AppCompatResources;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
Expand Down Expand Up @@ -103,31 +104,31 @@ public interface OnCheckedChangeListener {
* @see #setCheckedIconGravity(int)
* @see #getCheckedIconGravity()
*/
public static final int CHECKED_ICON_GRAVITY_TOP_START = 0x1;
public static final int CHECKED_ICON_GRAVITY_TOP_START = Gravity.TOP | Gravity.START;

/**
* Gravity used to position the checked icon at the bottom|start of the Card.
*
* @see #setCheckedIconGravity(int)
* @see #getCheckedIconGravity()
*/
public static final int CHECKED_ICON_GRAVITY_BOTTOM_START = 0x2;
public static final int CHECKED_ICON_GRAVITY_BOTTOM_START = Gravity.BOTTOM | Gravity.START;

/**
* Gravity used to position the checked icon at the top|end of the Card.
*
* @see #setCheckedIconGravity(int)
* @see #getCheckedIconGravity()
*/
public static final int CHECKED_ICON_GRAVITY_TOP_END = 0x3;
public static final int CHECKED_ICON_GRAVITY_TOP_END = Gravity.TOP | Gravity.END;

/**
* Gravity used to position the checked icon at the bottom|end of the Card.
*
* @see #setCheckedIconGravity(int)
* @see #getCheckedIconGravity()
*/
public static final int CHECKED_ICON_GRAVITY_BOTTOM_END = 0x4;
public static final int CHECKED_ICON_GRAVITY_BOTTOM_END = Gravity.BOTTOM | Gravity.END;

/** Positions the icon can be set to. */
@IntDef({
Expand Down
Expand Up @@ -19,8 +19,6 @@
import com.google.android.material.R;

import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
import static com.google.android.material.card.MaterialCardView.CHECKED_ICON_GRAVITY_BOTTOM_END;
import static com.google.android.material.card.MaterialCardView.CHECKED_ICON_GRAVITY_BOTTOM_START;
import static com.google.android.material.card.MaterialCardView.CHECKED_ICON_GRAVITY_TOP_END;

import android.content.res.ColorStateList;
Expand All @@ -38,6 +36,7 @@
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.core.view.ViewCompat;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import androidx.annotation.ColorInt;
import androidx.annotation.Dimension;
Expand Down Expand Up @@ -690,12 +689,10 @@ void setCheckedIconGravity(@CheckedIconGravity int checkedIconGravity) {
}

private boolean isCheckedIconEnd() {
return checkedIconGravity == CHECKED_ICON_GRAVITY_TOP_END
|| checkedIconGravity == CHECKED_ICON_GRAVITY_BOTTOM_END;
return (checkedIconGravity & Gravity.END) == Gravity.END;
}

private boolean isCheckedIconBottom() {
return checkedIconGravity == CHECKED_ICON_GRAVITY_BOTTOM_START
|| checkedIconGravity == CHECKED_ICON_GRAVITY_BOTTOM_END;
return (checkedIconGravity & Gravity.BOTTOM) == Gravity.BOTTOM;
}
}
16 changes: 8 additions & 8 deletions lib/java/com/google/android/material/card/res/values/attrs.xml
Expand Up @@ -47,14 +47,14 @@
<attr name="checkedIconMargin" format="dimension"/>
<!-- Specifies how the checked icon should be positioned. -->
<attr name="checkedIconGravity">
<!-- Push icon to the top|start of the card. -->
<flag name="TOP_START" value="0x1"/>
<!-- Push icon to the bottom|start of the card. -->
<flag name="BOTTOM_START" value="0x2"/>
<!-- Push icon to the top|end of the card. -->
<flag name="TOP_END" value="0x3"/>
<!-- Push icon to the bottom|end of the card. -->
<flag name="BOTTOM_END" value="0x4"/>
<!-- Gravity.TOP | Gravity.END -->
<enum name="TOP_END" value ="8388661"/>
<!-- Gravity.TOP | Gravity.START -->
<enum name="TOP_START" value ="8388659"/>
<!-- Gravity.BOTTOM | Gravity.END -->
<enum name="BOTTOM_END" value ="8388693"/>
<!-- Gravity.BOTTOM | Gravity.START -->
<enum name="BOTTOM_START" value ="8388691"/>
</attr>
<!-- Ripple color for the Card. -->
<attr name="rippleColor"/>
Expand Down

0 comments on commit bc56d5b

Please sign in to comment.