Skip to content

Instantly share code, notes, and snippets.

@maheswaranapk
Created October 17, 2019 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maheswaranapk/94a3281c3d5a2dd081dd535c0590a734 to your computer and use it in GitHub Desktop.
Save maheswaranapk/94a3281c3d5a2dd081dd535c0590a734 to your computer and use it in GitHub Desktop.
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