Last active
January 21, 2021 17:37
-
-
Save akexorcist/7e3c72a32814fffc25aaaf70ad60d0dc to your computer and use it in GitHub Desktop.
Build Coupon UI - Setup view attribute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CouponLayout : FrameLayout { | |
companion object { | |
const val SEMI_CIRCLE_NONE = 0x00 | |
const val SEMI_CIRCLE_LEFT = 0x01 | |
const val SEMI_CIRCLE_TOP = 0x02 | |
const val SEMI_CIRCLE_RIGHT = 0x04 | |
const val SEMI_CIRCLE_BOTTOM = 0x08 | |
const val SEMI_CIRCLE_HORIZONTAL = SEMI_CIRCLE_LEFT or SEMI_CIRCLE_RIGHT | |
const val SEMI_CIRCLE_VERTICAL = SEMI_CIRCLE_TOP or SEMI_CIRCLE_BOTTOM | |
const val SEMI_CIRCLE_ALL = SEMI_CIRCLE_HORIZONTAL or SEMI_CIRCLE_VERTICAL | |
const val CORNER_NONE = 0x00 | |
const val CORNER_TOP_LEFT = 0x01 | |
const val CORNER_TOP_RIGHT = 0x02 | |
const val CORNER_BOTTOM_LEFT = 0x04 | |
const val CORNER_BOTTOM_RIGHT = 0x08 | |
const val CORNER_TOP = CORNER_TOP_LEFT or CORNER_TOP_RIGHT | |
const val CORNER_BOTTOM = CORNER_BOTTOM_LEFT or CORNER_BOTTOM_RIGHT | |
const val CORNER_LEFT = CORNER_TOP_LEFT or CORNER_BOTTOM_LEFT | |
const val CORNER_RIGHT = CORNER_TOP_RIGHT or CORNER_BOTTOM_RIGHT | |
const val CORNER_ALL = CORNER_TOP_LEFT or CORNER_TOP_RIGHT or CORNER_BOTTOM_LEFT or CORNER_BOTTOM_RIGHT | |
} | |
private var borderWidth = 4f | |
private var cornerRadius = 32f | |
private var semiCircleRadius = 48f | |
private var backgroundPathColor = Color.WHITE | |
private var backgroundPathColorStateList: ColorStateList? = null | |
private var borderPathColor = Color.parseColor("#00000000") | |
private var borderPathColorStateList: ColorStateList? = null | |
private var cornerDirection = CORNER_ALL | |
private var semiCircleDirection = SEMI_CIRCLE_HORIZONTAL | |
/* ... */ | |
private fun setup(attrs: AttributeSet?, defStyleAttr: Int) { | |
/* ... */ | |
val attribute = context.obtainStyledAttributes(attrs, R.styleable.CouponLayout, defStyleAttr, 0) | |
borderWidth = attribute.getDimension(R.styleable.CouponLayout_coupon_borderWidth, 4f) | |
cornerRadius = attribute.getDimension(R.styleable.CouponLayout_coupon_cornerRadius, 32f) | |
semiCircleRadius = attribute.getDimension(R.styleable.CouponLayout_coupon_semiCircleRadius, 48f) | |
backgroundPathColor = attribute.getColor(R.styleable.CouponLayout_coupon_backgroundColor, Color.WHITE) | |
backgroundPathColorStateList = attribute.getColorStateList(R.styleable.CouponLayout_coupon_backgroundColor) | |
borderPathColor = attribute.getColor(R.styleable.CouponLayout_coupon_borderColor, Color.parseColor("#00000000")) | |
borderPathColorStateList = attribute.getColorStateList(R.styleable.CouponLayout_coupon_borderColor) | |
cornerDirection = attribute.getInt(R.styleable.CouponLayout_coupon_cornerDirection, CORNER_ALL) | |
semiCircleDirection = attribute.getInt(R.styleable.CouponLayout_coupon_semiCircleDirection, SEMI_CIRCLE_HORIZONTAL) | |
attribute.recycle() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment