Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.glance.Button
Expand Down Expand Up @@ -69,6 +70,7 @@ import androidx.glance.appwidget.action.ActionCallback
import androidx.glance.appwidget.action.actionRunCallback
import androidx.glance.appwidget.action.actionSendBroadcast
import androidx.glance.appwidget.action.actionStartService
import androidx.glance.appwidget.cornerRadius
import androidx.glance.appwidget.provideContent
import androidx.glance.appwidget.updateAll
import androidx.glance.appwidget.updateIf
Expand Down Expand Up @@ -868,6 +870,32 @@ object GlanceTheming {
}
}

object GlanceInnerPadding {

// [START android_compose_glance_innercornerradius]
/**
* Applies corner radius for views that are visually positioned [widgetPadding]dp inside of the
* widget background.
*/
@Composable
fun GlanceModifier.appWidgetInnerCornerRadius(widgetPadding: Dp): GlanceModifier {

if (Build.VERSION.SDK_INT < 31) {
return this
}

val resources = LocalContext.current.resources
// get dimension in float (without rounding).
val px = resources.getDimension(android.R.dimen.system_app_widget_background_radius)
val widgetBackgroundRadiusDpValue = px / resources.displayMetrics.density
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the helper function:

val widgetBackgroundRadiusDpValue =  with(LocalDensity.current){ intValue.toDp() }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LocalDensity isn't available during a glance composition. This is a glance snippet so the code would crash.

if (widgetBackgroundRadiusDpValue < widgetPadding.value) {
return this
}
return this.cornerRadius(Dp(widgetBackgroundRadiusDpValue - widgetPadding.value))
}
// [END android_compose_glance_innercornerradius]
}

object GlanceInteroperability {
@Composable
fun example01() {
Expand Down