Skip to content

Commit fbc7f4d

Browse files
committed
refactor
1 parent 3b12623 commit fbc7f4d

2 files changed

Lines changed: 1 addition & 40 deletions

File tree

samples/user-interface/appwidgets/src/main/java/com/example/platform/ui/appwidgets/glance/layout/text/layout/FullBleedImageLayout.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ private fun GalleryItemCard(
142142
modifier = GlanceModifier
143143
.fillMaxWidth()
144144
// Implementing a partial gradient scrim by applying a background modifier directly
145-
// to a text Column, shown here, results in the gradient stretching to fill the
145+
// to a text Column, shown here, results in the gradient stretching to fill the
146146
// entire widget. You can work around this by using an independent sibling Image
147147
// with a hardcoded height (100.dp) to restrict a gradient to the bottom.
148148
.background(ImageProvider(R.drawable.sample_scrim_gradient))

samples/user-interface/appwidgets/src/main/java/com/example/platform/ui/appwidgets/glance/layout/utils/FontUtils.kt

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -99,43 +99,4 @@ internal object FontUtils {
9999
val maxLines = (layoutHeight / textView.textSize).toInt().coerceAtLeast(1)
100100
return size.sp to maxLines
101101
}
102-
103-
/**
104-
* Returns a truncated version of the text with "..." if the text does not fit
105-
* within the available width at the given font size.
106-
*/
107-
fun truncateTextToFit(
108-
context: Context,
109-
text: String,
110-
fontSize: TextUnit,
111-
availableWidth: Dp,
112-
): String {
113-
fun dpToPx(dp: Dp): Int {
114-
return TypedValue.applyDimension(
115-
TypedValue.COMPLEX_UNIT_DIP,
116-
dp.value,
117-
context.resources.displayMetrics
118-
).toInt()
119-
}
120-
121-
val paint = android.text.TextPaint().apply {
122-
this.textSize = fontSize.value * context.resources.displayMetrics.scaledDensity
123-
}
124-
125-
val maxWidthPx = dpToPx(availableWidth)
126-
val textWidth = paint.measureText(text)
127-
128-
if (textWidth <= maxWidthPx) {
129-
return text
130-
}
131-
132-
val ellipsis = "..."
133-
val ellipsisWidth = paint.measureText(ellipsis)
134-
if (ellipsisWidth >= maxWidthPx) {
135-
return ellipsis
136-
}
137-
138-
val truncated = TextUtils.ellipsize(text, paint, maxWidthPx.toFloat(), TextUtils.TruncateAt.END)
139-
return truncated.toString()
140-
}
141102
}

0 commit comments

Comments
 (0)