Skip to content

Commit

Permalink
feat: Range android next timeline label
Browse files Browse the repository at this point in the history
Signed-off-by: Hu Shenghao <[email protected]>
  • Loading branch information
hushenghao committed Dec 4, 2024
1 parent 5a73159 commit 5e25e9f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.rememberTextMeasurer
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand All @@ -51,6 +52,7 @@ import com.dede.basic.requireDrawable
import com.google.accompanist.drawablepainter.rememberDrawablePainter
import kotlinx.coroutines.launch
import java.util.Calendar
import kotlin.math.floor
import kotlin.math.min

internal var androidNextDialogVisible by mutableStateOf(false)
Expand Down Expand Up @@ -168,16 +170,20 @@ private fun AndroidReleaseTimeline() {
.drawWithCache {
onDrawWithContent {
for (extra in labelExtras) {
val offsetX = size.width * extra.offsetXPercent
val rangeX = size.width * extra.rangeXPercent
val offsetY = size.height * extra.offsetYPercent
val textLayout = textMeasurer.measure(
text = context.getString(extra.labelRes),
style = TextStyle(
fontSize = 14.sp,
fontWeight = FontWeight.Bold,
fontFamily = FontFamily.SansSerif,
),
constraints = Constraints(
maxWidth = floor(rangeX - offsetX).toInt(),
)
)
val offsetX = size.width * extra.offsetXPercent
val offsetY = size.height * extra.offsetYPercent
drawText(
textLayoutResult = textLayout,
color = extra.color,
Expand Down
6 changes: 4 additions & 2 deletions eggs/AndroidNext/src/main/java/com/android_next/egg/Datas.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ internal data class LabelExtra(
@StringRes val labelRes: Int,
val color: Color,
val offsetXPercent: Float,
val offsetYPercent: Float = 35.2f / 180f,
val offsetYPercent: Float = 35f / 180f,
val rangeXPercent: Float = 1f
)

internal val labelExtras = arrayOf(
LabelExtra(
labelRes = R.string.label_timeline_developer_previews,
color = Color(0xFF_54585D),
offsetXPercent = 25f / 789f
offsetXPercent = 24f / 789f,
rangeXPercent = 204f / 789f,
),
LabelExtra(
labelRes = R.string.label_timeline_beta_release,
Expand Down

0 comments on commit 5e25e9f

Please sign in to comment.