Created
October 17, 2019 03:20
-
-
Save maheswaranapk/94a3281c3d5a2dd081dd535c0590a734 to your computer and use it in GitHub Desktop.
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 CircleIndicator : View { | |
private val paint = Paint() | |
private var centerX = 0F; | |
private var centerY = 0F; | |
private var radius = 0F; | |
constructor(context: Context) : super(context) | |
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) | |
override fun onAttachedToWindow() { | |
super.onAttachedToWindow() | |
paint.color = Color.RED; | |
paint.isAntiAlias = true | |
paint.style = Style.FILL | |
} | |
override fun onDraw(canvas: Canvas) { | |
super.onDraw(canvas) | |
canvas.drawCircle(centerX, centerY, radius, paint) | |
} | |
override fun onTouchEvent(event: MotionEvent?): Boolean { | |
Toast.makeText(context, "Hello !!!", Toast.LENGTH_LONG).show(); | |
return true; | |
} | |
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { | |
super.onSizeChanged(w, h, oldw, oldh) | |
centerX = w / 2F | |
centerY = h / 2F | |
radius = if (w < h) w / 2F else h / 2F | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment