Skip to content

Commit 5e25e9f

Browse files
committed
feat: Range android next timeline label
Signed-off-by: Hu Shenghao <dede.hu@qq.com>
1 parent 5a73159 commit 5e25e9f

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

eggs/AndroidNext/src/main/java/com/android_next/egg/AndroidNextTimelineDialog.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import androidx.compose.ui.text.font.FontFamily
4343
import androidx.compose.ui.text.font.FontWeight
4444
import androidx.compose.ui.text.rememberTextMeasurer
4545
import androidx.compose.ui.tooling.preview.Preview
46+
import androidx.compose.ui.unit.Constraints
4647
import androidx.compose.ui.unit.LayoutDirection
4748
import androidx.compose.ui.unit.dp
4849
import androidx.compose.ui.unit.sp
@@ -51,6 +52,7 @@ import com.dede.basic.requireDrawable
5152
import com.google.accompanist.drawablepainter.rememberDrawablePainter
5253
import kotlinx.coroutines.launch
5354
import java.util.Calendar
55+
import kotlin.math.floor
5456
import kotlin.math.min
5557

5658
internal var androidNextDialogVisible by mutableStateOf(false)
@@ -168,16 +170,20 @@ private fun AndroidReleaseTimeline() {
168170
.drawWithCache {
169171
onDrawWithContent {
170172
for (extra in labelExtras) {
173+
val offsetX = size.width * extra.offsetXPercent
174+
val rangeX = size.width * extra.rangeXPercent
175+
val offsetY = size.height * extra.offsetYPercent
171176
val textLayout = textMeasurer.measure(
172177
text = context.getString(extra.labelRes),
173178
style = TextStyle(
174179
fontSize = 14.sp,
175180
fontWeight = FontWeight.Bold,
176181
fontFamily = FontFamily.SansSerif,
177182
),
183+
constraints = Constraints(
184+
maxWidth = floor(rangeX - offsetX).toInt(),
185+
)
178186
)
179-
val offsetX = size.width * extra.offsetXPercent
180-
val offsetY = size.height * extra.offsetYPercent
181187
drawText(
182188
textLayoutResult = textLayout,
183189
color = extra.color,

eggs/AndroidNext/src/main/java/com/android_next/egg/Datas.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ internal data class LabelExtra(
77
@StringRes val labelRes: Int,
88
val color: Color,
99
val offsetXPercent: Float,
10-
val offsetYPercent: Float = 35.2f / 180f,
10+
val offsetYPercent: Float = 35f / 180f,
11+
val rangeXPercent: Float = 1f
1112
)
1213

1314
internal val labelExtras = arrayOf(
1415
LabelExtra(
1516
labelRes = R.string.label_timeline_developer_previews,
1617
color = Color(0xFF_54585D),
17-
offsetXPercent = 25f / 789f
18+
offsetXPercent = 24f / 789f,
19+
rangeXPercent = 204f / 789f,
1820
),
1921
LabelExtra(
2022
labelRes = R.string.label_timeline_beta_release,

0 commit comments

Comments
 (0)