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 { | |
/* ... */ | |
override fun onDraw(canvas: Canvas?) { | |
super.onDraw(canvas) | |
canvas?.let { _ -> | |
canvas.drawPath(backgroundPath, backgroundPaint) | |
canvas.drawPath(backgroundPath, borderPaint) | |
} | |
} | |
} |
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 { | |
private var cornerDirection = /* ... */ | |
private var semiCircleDirection = /* ... */ | |
/* ... */ | |
private fun setupPath() { | |
val isTopRightRequired = isCornerDirectionRequired(CORNER_TOP_RIGHT) | |
val isBottomRightRequired = isCornerDirectionRequired(CORNER_BOTTOM_RIGHT) | |
val isBottomLeftRequired = isCornerDirectionRequired(CORNER_BOTTOM_LEFT) | |
val isTopLeftRequired = isCornerDirectionRequired(CORNER_TOP_LEFT) | |
val isRightRequired = isSemiCircleDirectionRequired(SEMI_CIRCLE_RIGHT) |
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
const val SEMI_CIRCLE_BOTTOM = 0x08 | |
val semiCircleDirection = 0x0A | |
val isBottomSemiCicleRequired = semiCircleDirection and SEMI_CIRCLE_BOTTOM == SEMI_CIRCLE_BOTTOM | |
// true |
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 { | |
/* ... */ | |
private fun setupPath() { | |
path.apply { | |
reset() | |
moveTo(/* Start point */) | |
topRightCorner (areaWidth, areaHeight, borderWidth, cornerRadius) | |
rightSemiCircle (areaWidth, areaHeight, borderWidth, semiCircleRadius) | |
bottomRightCorner (areaWidth, areaHeight, borderWidth, cornerRadius) | |
bottomSemiCircle (areaWidth, areaHeight, borderWidth, semiCircleRadius) |
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 { | |
private var borderWidth = /* ... */ | |
private var backgroundPathColor = /* ... */ | |
private var backgroundPathColorStateList: ColorStateList? = /* ... */ | |
private var borderPathColor = /* ... */ | |
private var borderPathColorStateList: ColorStateList? = /* ... */ | |
/* ... */ | |
private val borderPaint = Paint().apply { isAntiAlias = true } | |
private val backgroundPaint = Paint().apply { isAntiAlias = true } | |
/* ... */ |
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 |
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
<LinearLayout> | |
<com.lmwn.library.ui.CouponLayout | |
android:layout_width="300dp" | |
android:layout_height="200dp" | |
app:coupon_backgroundColor="#EEEEEE" | |
app:coupon_borderColor="#20000000" | |
app:coupon_borderWidth="4dp" | |
app:coupon_cornerDirection="top" | |
app:coupon_cornerRadius="16dp" | |
app:coupon_semiCircleDirection="horizontal" |
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
<!-- res/values/attrs.xml --> | |
<resources> | |
<declare-styleable name="CouponLayout"> | |
<attr name="coupon_borderWidth" format="dimension" /> | |
<attr name="coupon_cornerRadius" format="dimension" /> | |
<attr name="coupon_semiCircleRadius" format="dimension" /> | |
<attr name="coupon_backgroundColor" format="color|reference" /> | |
<attr name="coupon_borderColor" format="color|reference" /> | |
<attr name="coupon_cornerDirection" format="enum"> | |
<enum name="none" value="0x00" /> |
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 { | |
constructor(context: Context) : super(context) { | |
setup(context, null, 0) | |
} | |
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) { | |
setup(context, attrs, 0) | |
} | |
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { |
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
### Start point | |
x = area_width - (corner_radius + (border_width / 2)) | |
y = border_width / 2 | |
### Top right corner | |
x1 = area_width - ((corner_radius * 2) + (border_width / 2)) | |
y1 = border_width / 2 | |
x2 = area_width - (border_width / 2) | |
y2 = (corner_radius * 2) + (border_width / 2) | |
start_angle = 270 |