plusonelabs / calendar-widget

An calender widget for your Android home screen.
Apache License 2.0
371 stars 126 forks source link

Rounded corners for the widget #352

Closed yvolk closed 4 years ago

yvolk commented 4 years ago

As Reboot Myth suggested "With the new phones having rounded screens, can the widget also support rounded rectangles?"

I found this discussion https://stackoverflow.com/questions/26074784/how-to-make-a-view-with-rounded-corners and it looks like we can achieve this using the CardView at the top of the Widget's views hierarchy: https://developer.android.com/jetpack/androidx/releases/cardview

The question remains how to make this rounding optional without additional widget redraws...

And here https://medium.com/@iamsadesh/android-ui-creating-a-layout-rounded-only-in-the-top-d60514ccab77 the author suggests to set outline for the parent view and then .setClipToOutline(true) on it...

val image = findViewById<ImageView>(R.id.image)
val curveRadius = 20F

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

    image.outlineProvider = object : ViewOutlineProvider() {

        @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
        override fun getOutline(view: View?, outline: Outline?) {
            outline?.setRoundRect(0, 0, view!!.width, (view.height+curveRadius).toInt(), curveRadius)
        }
    }

    image.clipToOutline = true

}
yvolk commented 4 years ago

Moved to the current issues list: https://github.com/andstatus/todoagenda/issues/16