feat: 워치 스킨에 기온·비 칩, 링을 누르면 그 각 상세로 열기, 앱 첫 장 제거
- 스킨 아래 기온·비 소식 칩, 날짜는 시계 밑으로. 빗줄기·눈송이는 비 소식 문구 기준 - 링·가운데 1위 탭 → 앱이 새로 열리며 그 각 상세 장부터 - 앱 첫 장(해 구슬·링)은 스킨과 겹쳐 삭제, 앱은 오늘의 각부터 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b72206f7ee
commit
7671dbeb19
11 files changed
+117
-237
No files matched your search
@@ -28,7 +28,7 @@ class GakComplicationService : SuspendingTimelineComplicationDataSourceService()
|
||||
val type = request.complicationType
|
||||
val sunset = s.sunset?.let { gakData(this, type, hhmm(it.bestAt), "노을", it.score, "sunset") }
|
||||
// 각 점수를 못 받았으면 노을이라도
|
||||
val default = s.myGak?.let { gakData(this, type, it.score.toString(), it.name.removeSuffix("각"), it.score, it.icon) } ?: sunset ?: return null
|
||||
val default = s.myGak?.let { gakData(this, type, it.score.toString(), it.name.removeSuffix("각"), it.score, it.icon, it.code) } ?: sunset ?: return null
|
||||
val entries = if (sunset == null) emptyList() else s.timeline.withIndex().filter { it.value.kind == "sunset" }.map { (i, p) ->
|
||||
val end = s.timeline.getOrNull(i + 1)?.startAt ?: p.startAt.plus(Duration.ofHours(3))
|
||||
TimelineEntry(TimeInterval(p.startAt, end), sunset)
|
||||
@@ -40,12 +40,16 @@ class GakComplicationService : SuspendingTimelineComplicationDataSourceService()
|
||||
}
|
||||
|
||||
/** 3D 아이콘은 작은 이미지로 함께 보낸다. 그릴지 말지는 시계 화면이 정한다. 누르면 날씨각 앱이 열린다. */
|
||||
fun gakData(context: Context, type: ComplicationType, text: String, title: String, score: Int, icon: String): ComplicationData {
|
||||
/** 누르면 앱이 열린다. code 를 주면 그 각 상세 장부터 */
|
||||
fun gakData(context: Context, type: ComplicationType, text: String, title: String, score: Int, icon: String, code: String? = null): ComplicationData {
|
||||
val img = SmallImage.Builder(Icon.createWithResource(context, iconRes(icon)), SmallImageType.ICON).build()
|
||||
val t = PlainComplicationText.Builder(text).build()
|
||||
val ti = PlainComplicationText.Builder(title).build()
|
||||
val desc = PlainComplicationText.Builder("$title $text").build()
|
||||
val open = PendingIntent.getActivity(context, 0, Intent(context, MainActivity::class.java), PendingIntent.FLAG_IMMUTABLE)
|
||||
// 각마다 다른 PendingIntent 여야 extra 가 섞이지 않고, 이미 열린 앱이 있어도 새로 열어야 누른 각이 첫 장에 온다
|
||||
val intent = Intent(context, MainActivity::class.java).putExtra(EXTRA_GAK, code)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK)
|
||||
val open = PendingIntent.getActivity(context, code.hashCode(), intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
return if (type == ComplicationType.RANGED_VALUE) {
|
||||
RangedValueComplicationData.Builder(score.toFloat(), 0f, 100f, desc).setText(t).setTitle(ti).setSmallImage(img).setTapAction(open).build()
|
||||
} else {
|
||||
|
||||
@@ -24,6 +24,9 @@ import kotlinx.coroutines.delay
|
||||
import java.time.Instant
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
/** 컴플리케이션 탭이 실어 보내는 각 코드 */
|
||||
const val EXTRA_GAK = "gak"
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
private var summary by mutableStateOf<Summary?>(null)
|
||||
private var loading by mutableStateOf(true)
|
||||
@@ -32,7 +35,8 @@ class MainActivity : ComponentActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContent { MaterialTheme { App(summary, loading) { load(force = true) } } }
|
||||
val opened = intent.getStringExtra(EXTRA_GAK)
|
||||
setContent { MaterialTheme { App(summary, loading, opened) { load(force = true) } } }
|
||||
if (checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) load()
|
||||
else askLocation.launch(Manifest.permission.ACCESS_COARSE_LOCATION)
|
||||
}
|
||||
@@ -46,10 +50,10 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private enum class Page { HERO, TOP, PICKS, SUNSET, HOURS }
|
||||
private enum class Page { DETAIL, TOP, PICKS, SUNSET, HOURS }
|
||||
|
||||
@Composable
|
||||
private fun App(s: Summary?, loading: Boolean, onRetry: () -> Unit) {
|
||||
private fun App(s: Summary?, loading: Boolean, opened: String?, onRetry: () -> Unit) {
|
||||
var now by remember { mutableStateOf(Instant.now()) }
|
||||
LaunchedEffect(Unit) {
|
||||
while (true) {
|
||||
@@ -61,28 +65,31 @@ private fun App(s: Summary?, loading: Boolean, onRetry: () -> Unit) {
|
||||
StatePage(loading, onRetry)
|
||||
return
|
||||
}
|
||||
// 받은 재료가 있는 장만
|
||||
// 스킨에서 누른 각이 있으면 그 상세부터, 아래로 넘기면 나머지 장
|
||||
val detail = opened?.let { c -> (s.top + s.picks).firstOrNull { it.code == c } }
|
||||
val pages = buildList {
|
||||
add(Page.HERO)
|
||||
if (detail != null) add(Page.DETAIL)
|
||||
if (s.top.isNotEmpty()) add(Page.TOP)
|
||||
if (s.picks.isNotEmpty()) add(Page.PICKS)
|
||||
if (s.sunset != null) add(Page.SUNSET)
|
||||
if (s.slots.isNotEmpty()) add(Page.HOURS)
|
||||
}
|
||||
if (pages.isEmpty()) {
|
||||
StatePage(loading = false, onRetry)
|
||||
return
|
||||
}
|
||||
val state = rememberPagerState { pages.size }
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
VerticalPager(state = state, modifier = Modifier.fillMaxSize()) { i ->
|
||||
when (pages[i]) {
|
||||
Page.HERO -> HeroPage(s, now)
|
||||
Page.DETAIL -> DetailPage(detail!!, now)
|
||||
Page.TOP -> GakListPage("오늘의 각", s.top.take(3), bgButter, medals = true, now)
|
||||
Page.PICKS -> GakListPage("내 각", s.picks, bgMint, medals = false, now)
|
||||
Page.SUNSET -> SunsetPage(s.sunset!!, now)
|
||||
Page.HOURS -> HoursPage(s, now)
|
||||
}
|
||||
}
|
||||
val page = pages[state.currentPage]
|
||||
val light = page == Page.SUNSET || (page == Page.HERO && isDark(s.mode))
|
||||
val dot = if (light) Color.White else Tok.ink
|
||||
val dot = if (pages[state.currentPage] == Page.SUNSET) Color.White else Tok.ink
|
||||
VerticalPageIndicator(pagerState = state, selectedColor = dot, unselectedColor = dot.copy(alpha = 0.35f), backgroundColor = Color.Transparent)
|
||||
}
|
||||
}
|
||||
@@ -8,19 +8,20 @@ import androidx.wear.watchface.complications.datasource.ComplicationRequest
|
||||
import androidx.wear.watchface.complications.datasource.SuspendingComplicationDataSourceService
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/** 워치 스킨의 숨은 칸용: 지금 비·눈 여부("rain" | "snow" | "none"). 스킨이 이 값을 보고 빗줄기·눈송이를 그린다. */
|
||||
/** 워치 스킨 아래 칩: 글자 = 지금 기온, 제목 = 비 소식. 스킨은 제목("비 와요"·"곧 비"·"눈 와요")을 보고 빗줄기·눈송이도 그린다. */
|
||||
class RainComplicationService : SuspendingComplicationDataSourceService() {
|
||||
|
||||
override suspend fun onComplicationRequest(request: ComplicationRequest): ComplicationData? {
|
||||
val s = withContext(Dispatchers.IO) { SummaryRepo.load(this@RainComplicationService) } ?: return null
|
||||
return data(s.precip ?: "none")
|
||||
return data(s.tempC?.let { "${it.roundToInt()}°" } ?: "-°", s.rainLabel)
|
||||
}
|
||||
|
||||
override fun getPreviewData(type: ComplicationType): ComplicationData = data("none")
|
||||
override fun getPreviewData(type: ComplicationType): ComplicationData = data("20°", "비 없음")
|
||||
|
||||
private fun data(kind: String) = ShortTextComplicationData.Builder(
|
||||
PlainComplicationText.Builder(kind).build(),
|
||||
PlainComplicationText.Builder(mapOf("rain" to "비", "snow" to "눈").getOrDefault(kind, "맑음")).build(),
|
||||
).build()
|
||||
private fun data(temp: String, rain: String) = ShortTextComplicationData.Builder(
|
||||
PlainComplicationText.Builder(temp).build(),
|
||||
PlainComplicationText.Builder("$temp $rain").build(),
|
||||
).setTitle(PlainComplicationText.Builder(rain).build()).build()
|
||||
}
|
||||
@@ -13,7 +13,7 @@ open class RankComplicationService(private val rank: Int) : SuspendingComplicati
|
||||
override suspend fun onComplicationRequest(request: ComplicationRequest): ComplicationData? {
|
||||
val s = withContext(Dispatchers.IO) { SummaryRepo.load(this@RankComplicationService) } ?: return null
|
||||
val g = s.top.getOrNull(rank - 1) ?: return null
|
||||
return gakData(this, request.complicationType, g.score.toString(), g.name, g.score, g.icon)
|
||||
return gakData(this, request.complicationType, g.score.toString(), g.name, g.score, g.icon, g.code)
|
||||
}
|
||||
|
||||
override fun getPreviewData(type: ComplicationType): ComplicationData = gakData(this, type, "${90 - rank * 2}", "${rank}위", 90 - rank * 2, "sun_cloud")
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package kr.o2o.nalssigak
|
||||
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.LinearEasing
|
||||
import androidx.compose.animation.core.RepeatMode
|
||||
import androidx.compose.animation.core.animateFloat
|
||||
import androidx.compose.animation.core.infiniteRepeatable
|
||||
@@ -13,7 +12,6 @@ import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
@@ -28,9 +26,6 @@ import androidx.compose.foundation.layout.widthIn
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.withFrameNanos
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
@@ -39,8 +34,6 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.drawBehind
|
||||
import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.geometry.CornerRadius
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.geometry.Size
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
@@ -62,11 +55,7 @@ import androidx.compose.ui.unit.sp
|
||||
import androidx.wear.compose.material3.Text
|
||||
import java.time.Duration
|
||||
import java.time.Instant
|
||||
import java.time.format.TextStyle as DateTextStyle
|
||||
import java.util.Locale
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.roundToInt
|
||||
import kotlin.math.sin
|
||||
|
||||
// 시안 크기는 큰 원형(227dp) 기준. 작은 원형(192dp)에서도 넘치지 않게 비율과 여백으로 잡는다.
|
||||
|
||||
@@ -102,187 +91,40 @@ fun Clock(now: Instant, color: Color) {
|
||||
T(hhmm(now), 11.sp, FontFamily.Default, color.copy(alpha = 0.8f), Modifier.fillMaxWidth().padding(top = 8.dp), weight = FontWeight.Bold)
|
||||
}
|
||||
|
||||
// ───────────── 1. 오늘 ─────────────
|
||||
|
||||
private val STARS = listOf(0.22f to 0.20f, 0.70f to 0.14f, 0.84f to 0.40f, 0.14f to 0.52f, 0.48f to 0.10f, 0.30f to 0.78f, 0.76f to 0.70f)
|
||||
// ───────────── 워치 스킨에서 누른 각 ─────────────
|
||||
|
||||
@Composable
|
||||
fun HeroPage(s: Summary, now: Instant) {
|
||||
val precip = s.precip
|
||||
val dark = isDark(s.mode)
|
||||
val night = s.mode == "night"
|
||||
val fg = if (dark) Color.White else Tok.ink
|
||||
val top = s.top.firstOrNull()
|
||||
BoxWithConstraints(Modifier.fillMaxSize().background(if (precip != null) precipBrush(precip, s.mode) else skyBrush(s.mode))) {
|
||||
val w = maxWidth
|
||||
if (night && precip == null) Canvas(Modifier.fillMaxSize()) {
|
||||
STARS.forEach { (x, y) -> drawCircle(Color.White, 1.4.dp.toPx(), Offset(size.width * x, size.height * y)) }
|
||||
}
|
||||
Clock(now, fg)
|
||||
val day = now.atZone(KST).dayOfWeek.getDisplayName(DateTextStyle.FULL, Locale.KOREAN)
|
||||
T("$day · ${s.regionName.substringAfterLast(' ')}", 12.sp, color = fg, modifier = Modifier.fillMaxWidth().padding(top = 26.dp))
|
||||
|
||||
val cloudColor = when { precip == "rain" -> Color(0xFFDCE2EB); night -> Color(0xFFC9CDF0); else -> Color.White }
|
||||
Cloud(cloudColor, 7000, 16f, Modifier.offset(w * 0.09f, w * 0.34f).size(w * 0.19f, w * 0.07f))
|
||||
Cloud(cloudColor, 9000, -20f, Modifier.offset(w * 0.6f, w * 0.74f).size(w * 0.22f, w * 0.075f))
|
||||
precip?.let { Precip(it, Modifier.fillMaxSize()) }
|
||||
if (!night) SunRays(Modifier.align(Alignment.Center).offset(y = (-6).dp).size(w * 0.5f))
|
||||
Orb(night, Modifier.align(Alignment.Center).offset(y = (-6).dp).size(w * 0.36f)) {
|
||||
T(top?.score?.toString() ?: "-", 32.sp, Tok.bagel, if (night) Color(0xFF2B2A5C) else Color.White)
|
||||
T(top?.name ?: "날씨각", 10.sp, color = if (night) Color(0xFF2B2A5C) else Color.White)
|
||||
}
|
||||
// 큰 원 둘레에 2~7위 점수 링 (워치 스킨과 같은 배치)
|
||||
val rings = s.top.drop(1).take(RING_ANGLES.size)
|
||||
rings.forEachIndexed { i, g ->
|
||||
val rad = Math.toRadians(RING_ANGLES[i])
|
||||
val size = w * 0.15f
|
||||
ScoreRing(g, dark, Modifier.offset(w * (0.5f + 0.33f * cos(rad).toFloat()) - size / 2, w * 0.5f - 6.dp + w * 0.33f * sin(rad).toFloat() - size / 2).size(size))
|
||||
}
|
||||
Row(Modifier.align(Alignment.BottomCenter).padding(bottom = w * 0.1f), horizontalArrangement = Arrangement.spacedBy(5.dp)) {
|
||||
Stat("thermo", s.tempC?.let { "${it.roundToInt()}°" } ?: "-°", dark)
|
||||
Stat("umbrella", when {
|
||||
precip == "snow" -> "눈 와요"
|
||||
s.nowIcon == "rain" -> "비 와요"
|
||||
s.rain2h == true -> "곧 비"
|
||||
s.rain2h == false -> "비 없음"
|
||||
else -> "-"
|
||||
}, dark)
|
||||
}
|
||||
s.warning?.let {
|
||||
T("⚠ $it", 10.sp, color = fg, modifier = Modifier.align(Alignment.BottomCenter).padding(bottom = w * 0.03f), maxLines = 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 링 자리 (0° = 오른쪽, 시계 방향). 위는 날짜, 아래는 칩이라 양옆으로 채운다
|
||||
private val RING_ANGLES = listOf(210.0, 330.0, 150.0, 30.0, 180.0, 0.0)
|
||||
|
||||
/** 작은 점수 링: 3D 아이콘 + 점수, 둘레에 점수만큼 주황 호 (시계 화면 컴플리케이션 모양) */
|
||||
@Composable
|
||||
private fun ScoreRing(g: Gak, dark: Boolean, modifier: Modifier) {
|
||||
val bg = if (dark) Tok.statDark else Tok.stat
|
||||
val track = if (dark) Color.White.copy(alpha = 0.2f) else Tok.shade
|
||||
Box(
|
||||
modifier.drawBehind {
|
||||
val stroke = 3.dp.toPx()
|
||||
drawCircle(bg)
|
||||
val arc = Size(size.width - stroke, size.height - stroke)
|
||||
val tl = Offset(stroke / 2, stroke / 2)
|
||||
drawArc(track, -90f, 360f, false, tl, arc, style = Stroke(stroke))
|
||||
drawArc(Tok.orange, -90f, 360f * g.score / 100f, false, tl, arc, style = Stroke(stroke, cap = StrokeCap.Round))
|
||||
},
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Ic(g.icon, 14.dp)
|
||||
T(g.score.toString(), 9.sp, Tok.bagel, if (dark) Color.White else Tok.ink)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 구슬 둘레의 끝이 둥근 햇살 12개. 1분에 한 바퀴 천천히 돈다 */
|
||||
@Composable
|
||||
private fun SunRays(modifier: Modifier) {
|
||||
val t = rememberInfiniteTransition(label = "rays")
|
||||
val turn by t.animateFloat(0f, 360f, infiniteRepeatable(tween(60_000, easing = LinearEasing)), label = "turn")
|
||||
Canvas(modifier.graphicsLayer { rotationZ = turn }) {
|
||||
val c = Offset(size.width / 2, size.height / 2)
|
||||
val r1 = size.width * 0.4f
|
||||
val r2 = size.width * 0.462f
|
||||
repeat(12) { i ->
|
||||
val a = Math.toRadians(i * 30.0)
|
||||
val dir = Offset(cos(a).toFloat(), sin(a).toFloat())
|
||||
drawLine(Color(0xFFFFB347), c + dir * r1, c + dir * r2, size.width * 0.044f, StrokeCap.Round)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 말랑 3D 해 구슬 (웹 .b-sun). 밤에는 달빛 보라 */
|
||||
@Composable
|
||||
private fun Orb(night: Boolean, modifier: Modifier, content: @Composable () -> Unit) {
|
||||
val stops = if (night) arrayOf(0f to Color.White, 0.35f to Color(0xFFE7E3FF), 0.72f to Color(0xFFB9B0F2), 1f to Color(0xFF8F86D9))
|
||||
else arrayOf(0f to Color(0xFFFFF5CF), 0.3f to Color(0xFFFFC86E), 0.68f to Color(0xFFFF8E4E), 1f to Color(0xFFEE6436))
|
||||
val glow = if (night) Color(0xFFBEB4FF) else Color(0xFFF06A3A)
|
||||
Box(
|
||||
modifier
|
||||
.shadow(18.dp, CircleShape, ambientColor = glow, spotColor = glow)
|
||||
.drawBehind {
|
||||
val c = Offset(size.width * 0.34f, size.height * 0.30f)
|
||||
drawCircle(Brush.radialGradient(*stops, center = c, radius = size.width * 0.96f))
|
||||
// 오른쪽 아래 그늘, 왼쪽 위 빛 (웹 inset 그림자 두 개)
|
||||
drawCircle(Brush.linearGradient(listOf(Color.Transparent, Color(if (night) 0x4D3C328C else 0x57AA3214)), Offset(size.width * 0.45f, size.height * 0.45f), Offset(size.width, size.height)))
|
||||
drawCircle(Brush.radialGradient(listOf(Color.White.copy(alpha = 0.45f), Color.Transparent), Offset(size.width * 0.28f, size.height * 0.25f), size.width * 0.35f))
|
||||
// 해에만 볼터치
|
||||
if (!night) listOf(0.18f, 0.82f).forEach { x ->
|
||||
drawOval(Color(0x73FF7A8A), Offset(size.width * x - size.width * 0.07f, size.height * 0.68f), Size(size.width * 0.14f, size.width * 0.08f))
|
||||
}
|
||||
},
|
||||
contentAlignment = Alignment.Center,
|
||||
) { Column(horizontalAlignment = Alignment.CenterHorizontally) { content() } }
|
||||
}
|
||||
|
||||
/** 구름은 좌우로 천천히 오간다. distance 부호로 방향, ms 로 속도 */
|
||||
@Composable
|
||||
private fun Cloud(c: Color, ms: Int, distance: Float, modifier: Modifier) {
|
||||
val t = rememberInfiniteTransition(label = "cloud")
|
||||
val p by t.animateFloat(0f, 1f, infiniteRepeatable(tween(ms, easing = FastOutSlowInEasing), RepeatMode.Reverse), label = "drift")
|
||||
Canvas(modifier.graphicsLayer { translationX = distance.dp.toPx() * p }) {
|
||||
drawCircle(c, size.height * 0.95f, Offset(size.width * 0.38f, size.height * 0.1f))
|
||||
drawRoundRect(c, cornerRadius = CornerRadius(size.height / 2))
|
||||
drawRoundRect(Color(0x33A0BEE6), Offset(0f, size.height * 0.55f), Size(size.width, size.height * 0.45f), CornerRadius(size.height / 2))
|
||||
}
|
||||
}
|
||||
|
||||
// 빗줄기·눈송이 하나: 가로 위치, 시작 위상, 한 번 떨어지는 데 걸리는 초, 크기 (모두 고정값이라 매번 같은 자리)
|
||||
private class Drop(val x: Float, val phase: Float, val sec: Float, val size: Float)
|
||||
|
||||
private val DROPS = java.util.Random(7).let { r -> List(42) { Drop(r.nextFloat(), r.nextFloat(), 0.7f + r.nextFloat() * 0.5f, 0.6f + r.nextFloat() * 0.4f) } }
|
||||
|
||||
/** 비는 추적추적 비스듬히, 눈은 천천히 흔들리며. 화면이 켜져 있는 동안만 그린다 */
|
||||
@Composable
|
||||
private fun Precip(kind: String, modifier: Modifier) {
|
||||
var time by remember { mutableFloatStateOf(0f) }
|
||||
LaunchedEffect(Unit) {
|
||||
val start = withFrameNanos { it }
|
||||
while (true) withFrameNanos { time = (it - start) / 1e9f }
|
||||
}
|
||||
val snow = kind == "snow"
|
||||
Canvas(modifier) {
|
||||
val h = size.height
|
||||
DROPS.forEachIndexed { i, d ->
|
||||
val period = if (snow) d.sec * 7f else d.sec
|
||||
val p = (time / period + d.phase) % 1f
|
||||
val y = p * (h + 40.dp.toPx()) - 20.dp.toPx()
|
||||
if (snow) {
|
||||
val x = d.x * size.width + sin((time / 2f + d.phase) * 2f * Math.PI.toFloat()) * 6.dp.toPx()
|
||||
drawCircle(Color.White.copy(alpha = 0.9f), (1.5f + 2f * d.size).dp.toPx(), Offset(x, y))
|
||||
} else {
|
||||
val len = 14.dp.toPx() * d.size
|
||||
val x = d.x * size.width + y * 0.12f
|
||||
drawLine(Color(0xCCEAF2FF), Offset(x, y), Offset(x - len * 0.12f, y - len), 1.5.dp.toPx(), StrokeCap.Round)
|
||||
// 셋 중 하나는 바닥에서 톡 튄다
|
||||
if (i % 3 == 0 && p > 0.86f) {
|
||||
val k = (p - 0.86f) / 0.14f
|
||||
drawCircle(Color(0x99EAF2FF), (2f + 6f * k).dp.toPx(), Offset(x, h * (0.8f + 0.12f * d.x)), style = Stroke(1.dp.toPx()), alpha = 1f - k)
|
||||
fun DetailPage(g: Gak, now: Instant) {
|
||||
Box(Modifier.fillMaxSize().background(bgButter)) {
|
||||
Clock(now, Tok.ink)
|
||||
Column(Modifier.fillMaxSize().padding(horizontal = 30.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) {
|
||||
Box(
|
||||
Modifier.size(96.dp).drawBehind {
|
||||
val stroke = 6.dp.toPx()
|
||||
val arc = Size(size.width - stroke, size.height - stroke)
|
||||
val tl = Offset(stroke / 2, stroke / 2)
|
||||
drawCircle(Tok.stat)
|
||||
drawArc(Tok.shade, -90f, 360f, false, tl, arc, style = Stroke(stroke))
|
||||
drawArc(Tok.orange, -90f, 360f * g.score / 100f, false, tl, arc, style = Stroke(stroke, cap = StrokeCap.Round))
|
||||
},
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||
Ic(g.icon, 36.dp)
|
||||
T(g.score.toString(), 24.sp, Tok.bagel, Tok.ink)
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.height(6.dp))
|
||||
T(g.name, 17.sp, color = Tok.ink)
|
||||
T("오늘 ${g.rank}위", 10.sp, FontFamily.Default, Tok.ink.copy(alpha = 0.7f), weight = FontWeight.Bold)
|
||||
g.summary?.let {
|
||||
Spacer(Modifier.height(6.dp))
|
||||
T(it, 11.sp, FontFamily.Default, Tok.ink, Modifier.mallang().padding(horizontal = 10.dp, vertical = 6.dp), maxLines = 3)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Stat(icon: String, text: String, dark: Boolean) {
|
||||
Row(
|
||||
Modifier.mallang(if (dark) Tok.statDark else Tok.stat, if (dark) Color.White.copy(alpha = 0.12f) else Tok.shade.copy(alpha = 0.9f), 14.dp)
|
||||
.padding(start = 5.dp, end = 9.dp, top = 3.dp, bottom = 6.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(3.dp),
|
||||
) {
|
||||
Ic(icon, 16.dp)
|
||||
T(text, 12.sp, color = if (dark) Color.White else Tok.ink)
|
||||
}
|
||||
}
|
||||
|
||||
// ───────────── 2·3. 오늘의 각 · 내 각 ─────────────
|
||||
|
||||
@Composable
|
||||
|
||||
@@ -49,6 +49,15 @@ data class Summary(
|
||||
nowIcon == "rain" || rain2h == true -> "rain"
|
||||
else -> null
|
||||
}
|
||||
|
||||
/** 스킨 칩의 비 소식. 비·눈 화면과 어긋나지 않게 precip 을 따른다 */
|
||||
val rainLabel: String get() = when {
|
||||
precip == "snow" -> "눈 와요"
|
||||
nowIcon == "rain" -> "비 와요"
|
||||
precip == "rain" -> "곧 비"
|
||||
rain2h == false -> "비 없음"
|
||||
else -> "-"
|
||||
}
|
||||
}
|
||||
|
||||
val KST: ZoneId = ZoneId.of("Asia/Seoul")
|
||||
|
||||
@@ -34,16 +34,6 @@ fun skyBrush(mode: String): Brush = when (mode) {
|
||||
else -> v(0f to 0xFF9FD3FF, 0.55f to 0xFFCFE9FF, 1f to 0xFFF1F8FF)
|
||||
}
|
||||
|
||||
/** 비·눈 오는 날 하늘. 밤에는 어두운 회청색 */
|
||||
fun precipBrush(kind: String, mode: String): Brush = when {
|
||||
mode == "night" -> v(0f to 0xFF1C2238, 0.6f to 0xFF2E3650, 1f to 0xFF434B66)
|
||||
kind == "snow" -> v(0f to 0xFFB8C4D6, 0.55f to 0xFFDFE6F0, 1f to 0xFFF4F7FB)
|
||||
else -> v(0f to 0xFF7F93AD, 0.55f to 0xFFA9B7C9, 1f to 0xFFD5DDE8)
|
||||
}
|
||||
|
||||
/** 하늘 위 글자가 흰색이어야 하는 시간대 */
|
||||
fun isDark(mode: String) = mode == "evening" || mode == "night"
|
||||
|
||||
// 카드·장 배경 (.b-bg-*)
|
||||
val bgButter = v(0f to 0xFFFFE7A0, 1f to 0xFFFFF6D8)
|
||||
val bgMint = v(0f to 0xFFBFECD6, 1f to 0xFFEFFAF4)
|
||||
|
||||
@@ -74,7 +74,7 @@ def mode_block(colors, pos, ink, night=False):
|
||||
if night:
|
||||
parts.append(stars())
|
||||
cc = "#FFC9CDF0" if night else "#FFFFFFFF"
|
||||
parts += [cloud(40, 160, 86, 30, 20, 10, cc), cloud(270, 345, 100, 32, -24, 12, cc), clock(ink)]
|
||||
parts += [cloud(40, 160, 86, 30, 20, 10, cc), cloud(270, 345, 100, 32, -24, 12, cc), clock(ink), date_line(ink)]
|
||||
return "\n ".join(parts)
|
||||
|
||||
def text(x, y, w, h, family, size, color, expr, amb=False):
|
||||
@@ -138,8 +138,17 @@ def ring_slot(i, angle):
|
||||
# 기기 언어와 상관없이 한글 요일 ([DAY_OF_WEEK] 1 = 일요일)
|
||||
WEEKDAY = " : ".join(f'[DAY_OF_WEEK] == {n + 1} ? "{d}"' for n, d in enumerate("일월화수목금")) + " : "토""
|
||||
|
||||
def chip(x, w, icon, expr):
|
||||
return f'''<PartDraw x="{x}" y="364" width="{w}" height="40">{AMB0}
|
||||
<RoundRectangle x="0" y="0" width="{w}" height="40" cornerRadiusX="20" cornerRadiusY="20"><Fill color="{CARD}"/></RoundRectangle>
|
||||
<RoundRectangle x="0" y="35" width="{w}" height="5" cornerRadiusX="2" cornerRadiusY="2"><Fill color="#E6D9E5F4"/></RoundRectangle>
|
||||
</PartDraw>
|
||||
<PartImage x="{x + 8}" y="370" width="26" height="26">{AMB0}<Image resource="e_{icon}"/></PartImage>
|
||||
{text(x + 32, 369, w - 38, 30, "jua", 21, INK, expr, amb=True)}'''
|
||||
|
||||
def precip_slot():
|
||||
"""화면 전체를 덮는 숨은 칸. 날씨각 앱(RainComplicationService)이 rain | snow | none 을 주면 빗줄기·눈송이를 그린다.
|
||||
"""화면 전체를 덮는 숨은 칸. 날씨각 앱(RainComplicationService)이 글자 = 기온, 제목 = 비 소식을 주면
|
||||
아래에 기온·비 칩을 그리고, 비 소식이 "비 와요"·"곧 비"면 빗줄기, "눈 와요"면 눈송이를 그린다.
|
||||
터치는 막지 않게 BoundingOval 을 1px 로 둔다. 주기는 60 의 약수여야 분이 바뀔 때 튀지 않는다."""
|
||||
import random
|
||||
r = random.Random(7)
|
||||
@@ -168,8 +177,8 @@ def precip_slot():
|
||||
<Complication type="SHORT_TEXT">
|
||||
<Condition>
|
||||
<Expressions>
|
||||
<Expression name="rain"><![CDATA[[COMPLICATION.TEXT] == "rain"]]></Expression>
|
||||
<Expression name="snow"><![CDATA[[COMPLICATION.TEXT] == "snow"]]></Expression>
|
||||
<Expression name="rain"><![CDATA[[COMPLICATION.TITLE] == "비 와요" || [COMPLICATION.TITLE] == "곧 비"]]></Expression>
|
||||
<Expression name="snow"><![CDATA[[COMPLICATION.TITLE] == "눈 와요"]]></Expression>
|
||||
</Expressions>
|
||||
<Compare expression="rain">
|
||||
{shade("#66485A78")}
|
||||
@@ -180,24 +189,22 @@ def precip_slot():
|
||||
{"".join(flakes)}
|
||||
</Compare>
|
||||
</Condition>
|
||||
{chip(108, 104, "thermo", "[COMPLICATION.TEXT]")}
|
||||
{chip(220, 122, "umbrella", "[COMPLICATION.TITLE]")}
|
||||
</Complication>
|
||||
<Complication type="EMPTY"/>
|
||||
</ComplicationSlot>'''
|
||||
|
||||
def date_chip():
|
||||
return f'''<PartDraw x="140" y="378" width="170" height="36">{AMB0}
|
||||
<RoundRectangle x="0" y="0" width="170" height="36" cornerRadiusX="18" cornerRadiusY="18"><Fill color="{CARD}"/></RoundRectangle>
|
||||
<RoundRectangle x="0" y="31" width="170" height="5" cornerRadiusX="2" cornerRadiusY="2"><Fill color="#E6D9E5F4"/></RoundRectangle>
|
||||
</PartDraw>
|
||||
<PartText x="140" y="380" width="170" height="30">{AMB0}
|
||||
<Text align="CENTER"><Font family="jua" size="19" color="{INK}"><Template><![CDATA[%d월 %d일 %s요일]]><Parameter expression="[MONTH]"/><Parameter expression="[DAY]"/><Parameter expression="{WEEKDAY}"/></Template></Font></Text>
|
||||
def date_line(ink):
|
||||
return f'''<PartText x="0" y="110" width="{W}" height="24">{AMB0}
|
||||
<Text align="CENTER"><Font family="jua" size="17" color="{ink}"><Template><![CDATA[%d월 %d일 %s요일]]><Parameter expression="[MONTH]"/><Parameter expression="[DAY]"/><Parameter expression="{WEEKDAY}"/></Template></Font></Text>
|
||||
</PartText>'''
|
||||
|
||||
exprs = "\n ".join(f'<Expression name="{k}"><![CDATA[{v[0].replace(">", ">").replace("<", "<").replace("&", "&")}]]></Expression>' for k, v in MODES.items())
|
||||
compares = "\n ".join(f'<Compare expression="{k}">\n {mode_block(v[1], v[2], v[3])}\n </Compare>' for k, v in MODES.items())
|
||||
|
||||
xml = f'''<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- 날씨각 워치 스킨. 앱 첫 장(HeroPage)과 같은 배치: 시간대 하늘, 해 구슬(1위), 둘레 링(2~7위). 점수는 날씨각 앱의 RankNComplicationService 가 공급한다.
|
||||
<!-- 날씨각 워치 스킨: 시간대 하늘, 해 구슬(1위), 둘레 링(2~7위), 아래 기온·비 칩. 링을 누르면 앱이 그 각 상세로 열린다. 점수는 날씨각 앱의 RankNComplicationService 가 공급한다.
|
||||
직접 고치지 말고 watch/watchface/gen_watchface.py 를 고친 뒤 다시 만든다: python3 gen_watchface.py src/main/res/raw/watchface.xml -->
|
||||
<WatchFace width="{W}" height="{W}">
|
||||
<Metadata key="CLOCK_TYPE" value="DIGITAL"/>
|
||||
@@ -224,7 +231,6 @@ xml = f'''<?xml version="1.0" encoding="UTF-8"?>
|
||||
{clock("#FFFFFFFF", ambient_visible=True)}
|
||||
{orb_slot()}
|
||||
{"".join(ring_slot(i, a) for i, a in enumerate(ANGLES))}
|
||||
{date_chip()}
|
||||
</Scene>
|
||||
</WatchFace>
|
||||
'''
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- 날씨각 워치 스킨. 앱 첫 장(HeroPage)과 같은 배치: 시간대 하늘, 해 구슬(1위), 둘레 링(2~7위). 점수는 날씨각 앱의 RankNComplicationService 가 공급한다.
|
||||
<!-- 날씨각 워치 스킨: 시간대 하늘, 해 구슬(1위), 둘레 링(2~7위), 아래 기온·비 칩. 링을 누르면 앱이 그 각 상세로 열린다. 점수는 날씨각 앱의 RankNComplicationService 가 공급한다.
|
||||
직접 고치지 말고 watch/watchface/gen_watchface.py 를 고친 뒤 다시 만든다: python3 gen_watchface.py src/main/res/raw/watchface.xml -->
|
||||
<WatchFace width="450" height="450">
|
||||
<Metadata key="CLOCK_TYPE" value="DIGITAL"/>
|
||||
@@ -31,6 +31,9 @@
|
||||
<Font family="bagel_fat_one" size="54" color="#FF28304A"/>
|
||||
</TimeText>
|
||||
</DigitalClock>
|
||||
<PartText x="0" y="110" width="450" height="24"><Variant mode="AMBIENT" target="alpha" value="0"/>
|
||||
<Text align="CENTER"><Font family="jua" size="17" color="#FF28304A"><Template><![CDATA[%d월 %d일 %s요일]]><Parameter expression="[MONTH]"/><Parameter expression="[DAY]"/><Parameter expression="[DAY_OF_WEEK] == 1 ? "일" : [DAY_OF_WEEK] == 2 ? "월" : [DAY_OF_WEEK] == 3 ? "화" : [DAY_OF_WEEK] == 4 ? "수" : [DAY_OF_WEEK] == 5 ? "목" : [DAY_OF_WEEK] == 6 ? "금" : "토""/></Template></Font></Text>
|
||||
</PartText>
|
||||
</Compare>
|
||||
<Compare expression="day">
|
||||
<PartDraw x="0" y="0" width="450" height="450"><Variant mode="AMBIENT" target="alpha" value="0"/>
|
||||
@@ -51,6 +54,9 @@
|
||||
<Font family="bagel_fat_one" size="54" color="#FF28304A"/>
|
||||
</TimeText>
|
||||
</DigitalClock>
|
||||
<PartText x="0" y="110" width="450" height="24"><Variant mode="AMBIENT" target="alpha" value="0"/>
|
||||
<Text align="CENTER"><Font family="jua" size="17" color="#FF28304A"><Template><![CDATA[%d월 %d일 %s요일]]><Parameter expression="[MONTH]"/><Parameter expression="[DAY]"/><Parameter expression="[DAY_OF_WEEK] == 1 ? "일" : [DAY_OF_WEEK] == 2 ? "월" : [DAY_OF_WEEK] == 3 ? "화" : [DAY_OF_WEEK] == 4 ? "수" : [DAY_OF_WEEK] == 5 ? "목" : [DAY_OF_WEEK] == 6 ? "금" : "토""/></Template></Font></Text>
|
||||
</PartText>
|
||||
</Compare>
|
||||
<Compare expression="evening">
|
||||
<PartDraw x="0" y="0" width="450" height="450"><Variant mode="AMBIENT" target="alpha" value="0"/>
|
||||
@@ -71,6 +77,9 @@
|
||||
<Font family="bagel_fat_one" size="54" color="#FFFFFFFF"/>
|
||||
</TimeText>
|
||||
</DigitalClock>
|
||||
<PartText x="0" y="110" width="450" height="24"><Variant mode="AMBIENT" target="alpha" value="0"/>
|
||||
<Text align="CENTER"><Font family="jua" size="17" color="#FFFFFFFF"><Template><![CDATA[%d월 %d일 %s요일]]><Parameter expression="[MONTH]"/><Parameter expression="[DAY]"/><Parameter expression="[DAY_OF_WEEK] == 1 ? "일" : [DAY_OF_WEEK] == 2 ? "월" : [DAY_OF_WEEK] == 3 ? "화" : [DAY_OF_WEEK] == 4 ? "수" : [DAY_OF_WEEK] == 5 ? "목" : [DAY_OF_WEEK] == 6 ? "금" : "토""/></Template></Font></Text>
|
||||
</PartText>
|
||||
</Compare>
|
||||
<Default>
|
||||
<PartDraw x="0" y="0" width="450" height="450"><Variant mode="AMBIENT" target="alpha" value="0"/>
|
||||
@@ -92,6 +101,9 @@
|
||||
<Font family="bagel_fat_one" size="54" color="#FFFFFFFF"/>
|
||||
</TimeText>
|
||||
</DigitalClock>
|
||||
<PartText x="0" y="110" width="450" height="24"><Variant mode="AMBIENT" target="alpha" value="0"/>
|
||||
<Text align="CENTER"><Font family="jua" size="17" color="#FFFFFFFF"><Template><![CDATA[%d월 %d일 %s요일]]><Parameter expression="[MONTH]"/><Parameter expression="[DAY]"/><Parameter expression="[DAY_OF_WEEK] == 1 ? "일" : [DAY_OF_WEEK] == 2 ? "월" : [DAY_OF_WEEK] == 3 ? "화" : [DAY_OF_WEEK] == 4 ? "수" : [DAY_OF_WEEK] == 5 ? "목" : [DAY_OF_WEEK] == 6 ? "금" : "토""/></Template></Font></Text>
|
||||
</PartText>
|
||||
</Default>
|
||||
</Condition>
|
||||
<!-- 주의: 칸(ComplicationSlot) 순서·slotId 를 바꿔 덮어 설치하면 기존 기기에서 공급원이 한 칸씩 밀린다 (에뮬레이터에서 확인). 새 칸은 맨 뒤에 붙인다 -->
|
||||
@@ -101,8 +113,8 @@
|
||||
<Complication type="SHORT_TEXT">
|
||||
<Condition>
|
||||
<Expressions>
|
||||
<Expression name="rain"><![CDATA[[COMPLICATION.TEXT] == "rain"]]></Expression>
|
||||
<Expression name="snow"><![CDATA[[COMPLICATION.TEXT] == "snow"]]></Expression>
|
||||
<Expression name="rain"><![CDATA[[COMPLICATION.TITLE] == "비 와요" || [COMPLICATION.TITLE] == "곧 비"]]></Expression>
|
||||
<Expression name="snow"><![CDATA[[COMPLICATION.TITLE] == "눈 와요"]]></Expression>
|
||||
</Expressions>
|
||||
<Compare expression="rain">
|
||||
<PartDraw x="0" y="0" width="450" height="450"><Variant mode="AMBIENT" target="alpha" value="0"/><Rectangle x="0" y="0" width="450" height="450"><Fill color="#66485A78"/></Rectangle></PartDraw>
|
||||
@@ -319,6 +331,22 @@
|
||||
</PartDraw>
|
||||
</Compare>
|
||||
</Condition>
|
||||
<PartDraw x="108" y="364" width="104" height="40"><Variant mode="AMBIENT" target="alpha" value="0"/>
|
||||
<RoundRectangle x="0" y="0" width="104" height="40" cornerRadiusX="20" cornerRadiusY="20"><Fill color="#B8FFFFFF"/></RoundRectangle>
|
||||
<RoundRectangle x="0" y="35" width="104" height="5" cornerRadiusX="2" cornerRadiusY="2"><Fill color="#E6D9E5F4"/></RoundRectangle>
|
||||
</PartDraw>
|
||||
<PartImage x="116" y="370" width="26" height="26"><Variant mode="AMBIENT" target="alpha" value="0"/><Image resource="e_thermo"/></PartImage>
|
||||
<PartText x="140" y="369" width="66" height="30"><Variant mode="AMBIENT" target="alpha" value="0"/>
|
||||
<Text align="CENTER" ellipsis="TRUE"><Font family="jua" size="21" color="#FF28304A"><Template><![CDATA[%s]]><Parameter expression="[COMPLICATION.TEXT]"/></Template></Font></Text>
|
||||
</PartText>
|
||||
<PartDraw x="220" y="364" width="122" height="40"><Variant mode="AMBIENT" target="alpha" value="0"/>
|
||||
<RoundRectangle x="0" y="0" width="122" height="40" cornerRadiusX="20" cornerRadiusY="20"><Fill color="#B8FFFFFF"/></RoundRectangle>
|
||||
<RoundRectangle x="0" y="35" width="122" height="5" cornerRadiusX="2" cornerRadiusY="2"><Fill color="#E6D9E5F4"/></RoundRectangle>
|
||||
</PartDraw>
|
||||
<PartImage x="228" y="370" width="26" height="26"><Variant mode="AMBIENT" target="alpha" value="0"/><Image resource="e_umbrella"/></PartImage>
|
||||
<PartText x="252" y="369" width="84" height="30"><Variant mode="AMBIENT" target="alpha" value="0"/>
|
||||
<Text align="CENTER" ellipsis="TRUE"><Font family="jua" size="21" color="#FF28304A"><Template><![CDATA[%s]]><Parameter expression="[COMPLICATION.TITLE]"/></Template></Font></Text>
|
||||
</PartText>
|
||||
</Complication>
|
||||
<Complication type="EMPTY"/>
|
||||
</ComplicationSlot>
|
||||
@@ -526,12 +554,5 @@
|
||||
</Complication>
|
||||
<Complication type="EMPTY"/>
|
||||
</ComplicationSlot>
|
||||
<PartDraw x="140" y="378" width="170" height="36"><Variant mode="AMBIENT" target="alpha" value="0"/>
|
||||
<RoundRectangle x="0" y="0" width="170" height="36" cornerRadiusX="18" cornerRadiusY="18"><Fill color="#B8FFFFFF"/></RoundRectangle>
|
||||
<RoundRectangle x="0" y="31" width="170" height="5" cornerRadiusX="2" cornerRadiusY="2"><Fill color="#E6D9E5F4"/></RoundRectangle>
|
||||
</PartDraw>
|
||||
<PartText x="140" y="380" width="170" height="30"><Variant mode="AMBIENT" target="alpha" value="0"/>
|
||||
<Text align="CENTER"><Font family="jua" size="19" color="#FF28304A"><Template><![CDATA[%d월 %d일 %s요일]]><Parameter expression="[MONTH]"/><Parameter expression="[DAY]"/><Parameter expression="[DAY_OF_WEEK] == 1 ? "일" : [DAY_OF_WEEK] == 2 ? "월" : [DAY_OF_WEEK] == 3 ? "화" : [DAY_OF_WEEK] == 4 ? "수" : [DAY_OF_WEEK] == 5 ? "목" : [DAY_OF_WEEK] == 6 ? "금" : "토""/></Template></Font></Text>
|
||||
</PartText>
|
||||
</Scene>
|
||||
</WatchFace>
|
||||
Reference in new issue
Block a user