1 /**
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * ```
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * ```
10  *
11  * Unless required by applicable law or agreed to in writing, software distributed under the License
12  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13  * or implied. See the License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 package com.android.healthconnect.controller.shared
17 
18 import android.content.Context
19 import android.graphics.Canvas
20 import android.graphics.Path
21 import android.util.AttributeSet
22 import android.widget.FrameLayout
23 
24 /** A view allowing to display content as round. */
25 class RoundView
26 @JvmOverloads
27 constructor(
28     context: Context,
29     attrs: AttributeSet? = null,
30     defStyleAttr: Int = 0,
31     defStyleRes: Int = 0,
32 ) : FrameLayout(context, attrs, defStyleAttr, defStyleRes) {
33 
34     private var clippingPath: Path = Path()
35 
36     init {
37         setWillNotDraw(false)
38     }
39 
onDrawnull40     override fun onDraw(canvas: Canvas) {
41         super.onDraw(canvas)
42         canvas.clipPath(clippingPath)
43     }
44 
onSizeChangednull45     override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
46         clippingPath = Path()
47         clippingPath.addOval(0f, 0f, w.toFloat(), h.toFloat(), Path.Direction.CCW)
48     }
49 }
50