x1 = area_width - ((semi_circle_radius / 2) + (border_width / 2))
y1 = (area_height / 2) - (semi_circle_radius / 2)
x2 = area_width + ((semi_circle_radius / 2) - (border_width / 2))
y2 = (area_height / 2) + (semi_circle_radius / 2)
start_angle = 270
sweep_angle = -180
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 |
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
val canvas: Canvas = /* ... */ | |
val areaWidth = canvas.width | |
val areaHeight = canvas.height | |
val borderWidth = 2 | |
val cornerRadius = 10 | |
val semiCircleRadius = 20 | |
val path = Path().apply { | |
/* ... */ | |
// Right edge semi circle |
start_angle = 270
sweep_angle = 90
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)