diff --git a/backend/router/v1/watch/watch.py b/backend/router/v1/watch/watch.py index ebc9874..757d34f 100644 --- a/backend/router/v1/watch/watch.py +++ b/backend/router/v1/watch/watch.py @@ -20,6 +20,8 @@ from services.weather_service import WeatherService router = APIRouter(prefix="/v1/watch", tags=["watch"]) MAX_PICKS = 3 +# 워치 스킨이 큰 원(1위) + 둘레 링 6개(2~7위)를 채운다 +TOP_N = 7 def _best(score: SkyScore, kind: str) -> datetime: @@ -37,7 +39,7 @@ def timeline(now: datetime, sunset: Optional[SkyScore], is_today: bool) -> list[ return items + [WatchTimeline(start_at=max(start, now), kind="sunset"), WatchTimeline(start_at=end, kind="gak")] -@router.get("/summary", response_model=Res_WatchSummary, response_model_exclude_none=True, summary="워치 한 번에: 지금 날씨, 각 1~3위·내 각, 노을, 남은 3시간 칸, 컴플리케이션 시간표") +@router.get("/summary", response_model=Res_WatchSummary, response_model_exclude_none=True, summary="워치 한 번에: 지금 날씨, 각 1~7위·내 각, 노을, 남은 3시간 칸, 컴플리케이션 시간표") async def get_watch_summary( region: str = Query(..., description="구 행정코드"), pick: Optional[str] = Query(None, description="내 각 코드, 쉼표로 최대 3개 (예: running,laundry)"), @@ -78,7 +80,7 @@ async def get_watch_summary( res.warning = now_w.warnings[0].text if now_w.warnings else None if board is not None: - res.top = [_top(i) for i in board.items[:3]] + res.top = [_top(i) for i in board.items[:TOP_N]] codes = [c.strip() for c in (pick or "").split(",") if c.strip()][:MAX_PICKS] by_code = {i.definition.code: i for i in board.items} res.picks = [_top(by_code[c]) for c in codes if c in by_code] diff --git a/backend/tests/test_watch.py b/backend/tests/test_watch.py index 7f887ad..e22bb28 100644 --- a/backend/tests/test_watch.py +++ b/backend/tests/test_watch.py @@ -48,7 +48,7 @@ async def test_watch_summary_bundles_now_top_picks_sunset(offline): assert body["region_code"] == REGION and body["mode"] in ("morning", "day", "evening", "night") assert body["refresh_at"] > body["issued_at"] assert body["now"]["rain_2h"] is False and body["now"]["temp_c"] == 20.0 - assert len(body["top"]) == 3 + assert [t["rank"] for t in body["top"]] == list(range(1, 8)) assert [p["code"] for p in body["picks"]] == ["laundry", "running"] assert body["sunset"]["best_at"] > body["sunset"]["sunset_at"] assert all(s["at"] > body["issued_at"] for s in body["slots"]) diff --git a/watch/app/src/main/AndroidManifest.xml b/watch/app/src/main/AndroidManifest.xml index 9b016c7..01402e0 100644 --- a/watch/app/src/main/AndroidManifest.xml +++ b/watch/app/src/main/AndroidManifest.xml @@ -34,6 +34,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + val end = s.timeline.getOrNull(i + 1)?.startAt ?: p.startAt.plus(Duration.ofHours(3)) TimelineEntry(TimeInterval(p.startAt, end), sunset) @@ -33,18 +36,19 @@ class GakComplicationService : SuspendingTimelineComplicationDataSourceService() return ComplicationDataTimeline(default, entries) } - override fun getPreviewData(type: ComplicationType): ComplicationData = data(type, "82", "야장", 82, "yajang") + override fun getPreviewData(type: ComplicationType): ComplicationData = gakData(this, type, "82", "야장", 82, "yajang") +} - /** 3D 아이콘은 작은 이미지로 함께 보낸다. 그릴지 말지는 시계 화면이 정한다. */ - private fun data(type: ComplicationType, text: String, title: String, score: Int, icon: String): ComplicationData { - val img = SmallImage.Builder(Icon.createWithResource(this, iconRes(icon)), SmallImageType.ICON).build() - val t = PlainComplicationText.Builder(text).build() - val ti = PlainComplicationText.Builder(title).build() - val desc = PlainComplicationText.Builder("$title $text").build() - return if (type == ComplicationType.RANGED_VALUE) { - RangedValueComplicationData.Builder(score.toFloat(), 0f, 100f, desc).setText(t).setTitle(ti).setSmallImage(img).build() - } else { - ShortTextComplicationData.Builder(t, desc).setTitle(ti).setSmallImage(img).build() - } +/** 3D 아이콘은 작은 이미지로 함께 보낸다. 그릴지 말지는 시계 화면이 정한다. 누르면 날씨각 앱이 열린다. */ +fun gakData(context: Context, type: ComplicationType, text: String, title: String, score: Int, icon: String): 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) + return if (type == ComplicationType.RANGED_VALUE) { + RangedValueComplicationData.Builder(score.toFloat(), 0f, 100f, desc).setText(t).setTitle(ti).setSmallImage(img).setTapAction(open).build() + } else { + ShortTextComplicationData.Builder(t, desc).setTitle(ti).setSmallImage(img).setTapAction(open).build() } } diff --git a/watch/app/src/main/java/kr/o2o/nalssigak/MainActivity.kt b/watch/app/src/main/java/kr/o2o/nalssigak/MainActivity.kt index ea5d7b1..be68e00 100644 --- a/watch/app/src/main/java/kr/o2o/nalssigak/MainActivity.kt +++ b/watch/app/src/main/java/kr/o2o/nalssigak/MainActivity.kt @@ -74,7 +74,7 @@ private fun App(s: Summary?, loading: Boolean, onRetry: () -> Unit) { VerticalPager(state = state, modifier = Modifier.fillMaxSize()) { i -> when (pages[i]) { Page.HERO -> HeroPage(s, now) - Page.TOP -> GakListPage("오늘의 각", s.top, bgButter, medals = true, 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) diff --git a/watch/app/src/main/java/kr/o2o/nalssigak/RainComplicationService.kt b/watch/app/src/main/java/kr/o2o/nalssigak/RainComplicationService.kt new file mode 100644 index 0000000..0d111d9 --- /dev/null +++ b/watch/app/src/main/java/kr/o2o/nalssigak/RainComplicationService.kt @@ -0,0 +1,26 @@ +package kr.o2o.nalssigak + +import androidx.wear.watchface.complications.data.ComplicationData +import androidx.wear.watchface.complications.data.ComplicationType +import androidx.wear.watchface.complications.data.PlainComplicationText +import androidx.wear.watchface.complications.data.ShortTextComplicationData +import androidx.wear.watchface.complications.datasource.ComplicationRequest +import androidx.wear.watchface.complications.datasource.SuspendingComplicationDataSourceService +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext + +/** 워치 스킨의 숨은 칸용: 지금 비·눈 여부("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") + } + + override fun getPreviewData(type: ComplicationType): ComplicationData = data("none") + + private fun data(kind: String) = ShortTextComplicationData.Builder( + PlainComplicationText.Builder(kind).build(), + PlainComplicationText.Builder(mapOf("rain" to "비", "snow" to "눈").getOrDefault(kind, "맑음")).build(), + ).build() +} diff --git a/watch/app/src/main/java/kr/o2o/nalssigak/RankComplicationService.kt b/watch/app/src/main/java/kr/o2o/nalssigak/RankComplicationService.kt new file mode 100644 index 0000000..9c77e79 --- /dev/null +++ b/watch/app/src/main/java/kr/o2o/nalssigak/RankComplicationService.kt @@ -0,0 +1,28 @@ +package kr.o2o.nalssigak + +import androidx.wear.watchface.complications.data.ComplicationData +import androidx.wear.watchface.complications.data.ComplicationType +import androidx.wear.watchface.complications.datasource.ComplicationRequest +import androidx.wear.watchface.complications.datasource.SuspendingComplicationDataSourceService +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext + +/** 워치 스킨용 N위 각. 칸 하나에 공급원 하나라 순위마다 서비스를 하나씩 둔다 (큰 원 1위, 둘레 링 2~7위). */ +open class RankComplicationService(private val rank: Int) : SuspendingComplicationDataSourceService() { + + 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) + } + + override fun getPreviewData(type: ComplicationType): ComplicationData = gakData(this, type, "${90 - rank * 2}", "${rank}위", 90 - rank * 2, "sun_cloud") +} + +class Rank1ComplicationService : RankComplicationService(1) +class Rank2ComplicationService : RankComplicationService(2) +class Rank3ComplicationService : RankComplicationService(3) +class Rank4ComplicationService : RankComplicationService(4) +class Rank5ComplicationService : RankComplicationService(5) +class Rank6ComplicationService : RankComplicationService(6) +class Rank7ComplicationService : RankComplicationService(7) diff --git a/watch/app/src/main/java/kr/o2o/nalssigak/Screens.kt b/watch/app/src/main/java/kr/o2o/nalssigak/Screens.kt index c9ad660..6d1fdc8 100644 --- a/watch/app/src/main/java/kr/o2o/nalssigak/Screens.kt +++ b/watch/app/src/main/java/kr/o2o/nalssigak/Screens.kt @@ -1,6 +1,7 @@ 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 @@ -27,6 +28,9 @@ 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 @@ -104,27 +108,31 @@ private val STARS = listOf(0.22f to 0.20f, 0.70f to 0.14f, 0.84f to 0.40f, 0.14f @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(skyBrush(s.mode))) { + BoxWithConstraints(Modifier.fillMaxSize().background(if (precip != null) precipBrush(precip, s.mode) else skyBrush(s.mode))) { val w = maxWidth - if (night) Canvas(Modifier.fillMaxSize()) { + 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)) - Cloud(night, 7000, 16f, Modifier.offset(w * 0.09f, w * 0.34f).size(w * 0.19f, w * 0.07f)) - Cloud(night, 9000, -20f, Modifier.offset(w * 0.6f, w * 0.74f).size(w * 0.22f, w * 0.075f)) - Orb(night, Modifier.align(Alignment.Center).offset(y = (-6).dp).size(w * 0.4f)) { - T(top?.score?.toString() ?: "-", 36.sp, Tok.bagel, if (night) Color(0xFF2B2A5C) else Color.White) - T(top?.name ?: "날씨각", 11.sp, color = if (night) Color(0xFF2B2A5C) else Color.White) + 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) } - // 큰 원 둘레에 나머지 각 점수 링 (1위는 큰 원에 있으니 빼고) - val rings = (s.top + s.picks).distinctBy { it.code }.filter { it.code != top?.code }.take(RING_ANGLES.size) + // 큰 원 둘레에 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 @@ -132,7 +140,13 @@ fun HeroPage(s: Summary, now: Instant) { } 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 (s.rain2h) { true -> "곧 비"; false -> "비 없음"; null -> "-" }, 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) @@ -166,6 +180,23 @@ private fun ScoreRing(g: Gak, dark: Boolean, modifier: Modifier) { } } +/** 구슬 둘레의 끝이 둥근 햇살 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) { @@ -181,6 +212,10 @@ private fun Orb(night: Boolean, modifier: Modifier, content: @Composable () -> U // 오른쪽 아래 그늘, 왼쪽 위 빛 (웹 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() } } @@ -188,8 +223,7 @@ private fun Orb(night: Boolean, modifier: Modifier, content: @Composable () -> U /** 구름은 좌우로 천천히 오간다. distance 부호로 방향, ms 로 속도 */ @Composable -private fun Cloud(night: Boolean, ms: Int, distance: Float, modifier: Modifier) { - val c = if (night) Color(0xFFC9CDF0) else Color.White +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 }) { @@ -199,6 +233,43 @@ private fun Cloud(night: Boolean, ms: Int, distance: Float, modifier: Modifier) } } +// 빗줄기·눈송이 하나: 가로 위치, 시작 위상, 한 번 떨어지는 데 걸리는 초, 크기 (모두 고정값이라 매번 같은 자리) +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) + } + } + } + } +} + @Composable private fun Stat(icon: String, text: String, dark: Boolean) { Row( diff --git a/watch/app/src/main/java/kr/o2o/nalssigak/Summary.kt b/watch/app/src/main/java/kr/o2o/nalssigak/Summary.kt index abb8e3a..566b10d 100644 --- a/watch/app/src/main/java/kr/o2o/nalssigak/Summary.kt +++ b/watch/app/src/main/java/kr/o2o/nalssigak/Summary.kt @@ -1,10 +1,13 @@ package kr.o2o.nalssigak import android.Manifest +import android.content.ComponentName import android.content.Context import android.content.pm.PackageManager import android.location.LocationManager import android.util.Log +import androidx.wear.tiles.TileService +import androidx.wear.watchface.complications.datasource.ComplicationDataSourceUpdateRequester import org.json.JSONArray import org.json.JSONObject import java.io.IOException @@ -26,6 +29,8 @@ data class Summary( /** morning | day | evening | night (서버 slot_of) */ val mode: String, val tempC: Double?, + /** 지금 3시간 칸 아이콘 (sun, rain, snow …) */ + val nowIcon: String?, val rainText: String?, val rain2h: Boolean?, val warning: String?, @@ -37,6 +42,13 @@ data class Summary( ) { /** 컴플리케이션·타일에 올릴 각: 내 각 첫 번째, 없으면 오늘 1위 */ val myGak: Gak? get() = picks.firstOrNull() ?: top.firstOrNull() + + /** 비·눈 화면: "rain" | "snow" | null. 지금 칸이 눈이면 눈, 지금 칸이 비거나 2시간 안에 비 소식이면 비 */ + val precip: String? get() = when { + nowIcon == "snow" -> "snow" + nowIcon == "rain" || rain2h == true -> "rain" + else -> null + } } val KST: ZoneId = ZoneId.of("Asia/Seoul") @@ -63,6 +75,7 @@ fun parseSummary(json: String): Summary { refreshAt = time(o.getString("refresh_at")), mode = o.optString("mode", "day"), tempC = now?.dbl("temp_c"), + nowIcon = now?.str("icon"), rainText = now?.str("text"), rain2h = now?.takeIf { it.has("rain_2h") }?.getBoolean("rain_2h"), warning = o.str("warning"), @@ -84,7 +97,13 @@ object SummaryRepo { private const val DEFAULT_REGION = "1111000000" /** 캐시가 refresh_at 전이면 캐시, 아니면 새로 받는다. 받기 실패하면 지난 캐시라도. 네트워크를 쓰니 메인 스레드에서 부르지 않는다. */ - fun load(context: Context, force: Boolean = false): Summary? { + fun load(context: Context, force: Boolean = false): Summary? = fetch(context, force)?.let { s -> + // 디버그 빌드 확인용: shared_prefs/debug.xml 의 precip(rain|snow)로 비·눈 화면을 강제로 띄운다 + val forced = if (BuildConfig.DEBUG) context.getSharedPreferences("debug", Context.MODE_PRIVATE).getString("precip", null) else null + if (forced == null) s else s.copy(nowIcon = forced, rain2h = forced == "rain") + } + + private fun fetch(context: Context, force: Boolean): Summary? { val prefs = context.getSharedPreferences("summary", Context.MODE_PRIVATE) val cached = prefs.getString("json", null)?.let { runCatching { parseSummary(it) }.getOrNull() } if (!force && cached != null && Instant.now() < cached.refreshAt) return cached @@ -93,6 +112,7 @@ object SummaryRepo { val json = get("/v1/watch/summary?region=$region&pick=$PICKS") val fresh = parseSummary(json) prefs.edit().putString("json", json).apply() + refreshSurfaces(context) fresh } catch (e: Exception) { Log.w(TAG, "summary 받기 실패, 캐시 사용", e) @@ -100,6 +120,16 @@ object SummaryRepo { } } + /** 새 값을 받으면 시계 화면 칸·타일을 모두 다시 그리게 한다. 칸마다 갱신 시점이 달라 순위가 섞이는 걸 막는다. + * 다시 불린 칸들은 방금 저장한 캐시를 읽으니 서버를 또 부르지 않는다. */ + private fun refreshSurfaces(context: Context) { + val sources = listOf(GakComplicationService::class.java, RainComplicationService::class.java, Rank1ComplicationService::class.java, + Rank2ComplicationService::class.java, Rank3ComplicationService::class.java, Rank4ComplicationService::class.java, + Rank5ComplicationService::class.java, Rank6ComplicationService::class.java, Rank7ComplicationService::class.java) + sources.forEach { ComplicationDataSourceUpdateRequester.create(context, ComponentName(context, it)).requestUpdateAll() } + TileService.getUpdater(context).requestUpdate(GakTileService::class.java) + } + private fun nearestRegion(context: Context): String? { if (context.checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) return null val lm = context.getSystemService(LocationManager::class.java) diff --git a/watch/app/src/main/java/kr/o2o/nalssigak/Theme.kt b/watch/app/src/main/java/kr/o2o/nalssigak/Theme.kt index 573be8d..ca0ec9f 100644 --- a/watch/app/src/main/java/kr/o2o/nalssigak/Theme.kt +++ b/watch/app/src/main/java/kr/o2o/nalssigak/Theme.kt @@ -34,6 +34,13 @@ 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" diff --git a/watch/settings.gradle.kts b/watch/settings.gradle.kts index 696374a..5a1993b 100644 --- a/watch/settings.gradle.kts +++ b/watch/settings.gradle.kts @@ -12,4 +12,4 @@ dependencyResolutionManagement { } } rootProject.name = "nalssigak-watch" -include(":app") +include(":app", ":watchface") diff --git a/watch/watchface/build.gradle.kts b/watch/watchface/build.gradle.kts new file mode 100644 index 0000000..4de48b6 --- /dev/null +++ b/watch/watchface/build.gradle.kts @@ -0,0 +1,19 @@ +plugins { + id("com.android.application") +} + +// 코드 없는 워치 스킨(Watch Face Format). 점수는 날씨각 앱(:app)의 순위별 컴플리케이션이 공급한다. +android { + enableKotlin = false + namespace = "kr.o2o.nalssigak.watchface" + compileSdk = 37 + + defaultConfig { + applicationId = "kr.o2o.nalssigak.watchface" + // WFF 버전 2 는 Wear OS 5(API 34)부터 + minSdk = 34 + targetSdk = 34 + versionCode = 1 + versionName = "0.1" + } +} diff --git a/watch/watchface/gen_watchface.py b/watch/watchface/gen_watchface.py new file mode 100644 index 0000000..3da2bfe --- /dev/null +++ b/watch/watchface/gen_watchface.py @@ -0,0 +1,231 @@ +import json, math, os, sys +HERE = os.path.dirname(os.path.abspath(__file__)) +# 각 이름 → 아이콘. 시계 런타임이 점수 링 안의 작은 이미지를 그려 주지 않아, 이름을 보고 스킨에 넣은 아이콘을 고른다 +GAK_ICONS = [(d["name"], d["icon"]) for d in json.load(open(os.path.join(HERE, "../../backend/seed/index_definition.json"), encoding="utf-8"))] +W = 450 +CX, CY = 225, 235 +ORB = 162 +RING, RR = 68, 148 +ANGLES = [210, 330, 150, 30, 180, 0] +APP = "kr.o2o.nalssigak" +INK, ORANGE, SHADE, CARD = "#FF28304A", "#FFFF7A45", "#FFD9E5F4", "#B8FFFFFF" +AMB0 = '' + +MODES = { # 웹 .b-hero[data-t] 그라데이션, 시간대는 고정 시각 근사 + "morning": ("[HOUR_0_23] >= 5 && [HOUR_0_23] < 11", "#FFFFD9B8 #FFFFE9D4 #FFDFF0FF", "0 0.4 1", INK), + "day": ("[HOUR_0_23] >= 11 && [HOUR_0_23] < 16", "#FF9FD3FF #FFCFE9FF #FFF1F8FF", "0 0.55 1", INK), + "evening": ("[HOUR_0_23] >= 16 && [HOUR_0_23] < 21", "#FF8E7CF0 #FFF28AA0 #FFFFC38A", "0 0.48 1", "#FFFFFFFF"), +} +NIGHT = ("#FF141B3D #FF27306A #FF3D3F86", "0 0.6 1", "#FFFFFFFF") +STARS = [(0.22, 0.20), (0.70, 0.14), (0.84, 0.40), (0.14, 0.52), (0.48, 0.10), (0.30, 0.78), (0.76, 0.70)] + +def sky(colors, pos): + return f'''{AMB0} + + ''' + +def clock(color, ambient_visible=False): + alpha = "0" if ambient_visible else "255" + var = '' if ambient_visible else AMB0 + return f''' + {var} + + + ''' + +def stars(): + dots = "".join(f'' for x, y in STARS) + return f'{AMB0}{dots}' + +def cloud(x, y, w, h, dist, period, color="#FFFFFFFF"): + # 화면이 켜져 있는 동안만 period 초마다 부드럽게 한 번 왕복 (period 는 60 의 약수여야 분이 바뀔 때 튀지 않는다). 저전력 화면에서는 숨긴다 + return f'''{AMB0} + + + + ''' + +def orb_fill(colors): + blush = "" if colors == MOON else "".join( + f'' for x in (0.2, 0.8)) + return f'''{AMB0} + + + {blush} + ''' + +SUN = "#FFFFF5CF #FFFFC86E #FFFF8E4E #FFEE6436" +MOON = "#FFFFFFFF #FFD9D3FF #FFA99FEA #FF7F75CC" + +def sun_rays(): + """구슬 둘레의 끝이 둥근 햇살 12개. 1분에 한 바퀴""" + size = int(ORB / 0.72) + c, r1, r2 = size / 2, size * 0.4, size * 0.462 + lines = "".join( + f'' + for a in range(0, 360, 30)) + return f'''{AMB0} + {lines} + + ''' + +def mode_block(colors, pos, ink, night=False): + parts = [sky(colors, pos)] + 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)] + return "\n ".join(parts) + +def text(x, y, w, h, family, size, color, expr, amb=False): + return f'''{AMB0 if amb else ""} + + ''' + +def orb_slot(): + x, y = CX - ORB // 2, CY - ORB // 2 + body = text(0, 30, ORB, 74, "bagel_fat_one", 58, "#FFFFFFFF", "[COMPLICATION.TEXT]") + text(14, 100, ORB - 28, 30, "jua", 21, "#FFFFFFFF", "[COMPLICATION.TITLE]") + return f''' + + + + {body} + + + {body} + + + ''' + +PROGRESS = "clamp([COMPLICATION.RANGED_VALUE_VALUE], [COMPLICATION.RANGED_VALUE_MIN], [COMPLICATION.RANGED_VALUE_MAX]) / ([COMPLICATION.RANGED_VALUE_MAX] - [COMPLICATION.RANGED_VALUE_MIN]) * 360" + +def icon_by_title(x, y, size): + exprs = "".join(f'' for n, (name, _) in enumerate(GAK_ICONS)) + cmps = "".join(f'{AMB0}' + for n, (_, icon) in enumerate(GAK_ICONS)) + return f"{exprs}{cmps}" + +def ring_slot(i, angle): + r = math.radians(angle) + x = int(CX + RR * math.cos(r) - RING / 2) + y = int(CY + RR * math.sin(r) - RING / 2) + s, a = RING, RING - 6 + return f''' + + + + {AMB0} + + + {AMB0} + + + + + + {icon_by_title(s // 2 - 14, 9, 28)} + {text(0, 35, s, 24, "bagel_fat_one", 18, INK, "[COMPLICATION.TEXT]", amb=True)} + + + {AMB0} + + + {text(0, 22, s, 24, "bagel_fat_one", 18, INK, "[COMPLICATION.TEXT]", amb=True)} + + + ''' + +# 기기 언어와 상관없이 한글 요일 ([DAY_OF_WEEK] 1 = 일요일) +WEEKDAY = " : ".join(f'[DAY_OF_WEEK] == {n + 1} ? "{d}"' for n, d in enumerate("일월화수목금")) + " : "토"" + +def precip_slot(): + """화면 전체를 덮는 숨은 칸. 날씨각 앱(RainComplicationService)이 rain | snow | none 을 주면 빗줄기·눈송이를 그린다. + 터치는 막지 않게 BoundingOval 을 1px 로 둔다. 주기는 60 의 약수여야 분이 바뀔 때 튀지 않는다.""" + import random + r = random.Random(7) + drops, flakes = [], [] + for i in range(34): + x, ph = r.randint(0, W), r.random() + period = r.choice([1, 1.2, 1.5]) + ln = r.randint(16, 26) + drops.append(f'''{AMB0} + + + ''') + for i in range(26): + x, ph = r.randint(0, W), r.random() + period = r.choice([6, 10, 12]) + d = r.randint(5, 10) + flakes.append(f'''{AMB0} + + + + ''') + shade = lambda c: f'{AMB0}' + return f''' + + + + + + + + + + {shade("#66485A78")} + {"".join(drops)} + + + {shade("#40A0AEC4")} + {"".join(flakes)} + + + + + ''' + +def date_chip(): + return f'''{AMB0} + + + + {AMB0} + + ''' + +exprs = "\n ".join(f'").replace("<", "<").replace("&", "&")}]]>' for k, v in MODES.items()) +compares = "\n ".join(f'\n {mode_block(v[1], v[2], v[3])}\n ' for k, v in MODES.items()) + +xml = f''' + + + + + + + + + {exprs} + + {compares} + + {mode_block(NIGHT[0], NIGHT[1], NIGHT[2], night=True)} + + + + {precip_slot()} + + + = 21]]> + {orb_fill(MOON)} + {sun_rays()}{orb_fill(SUN)} + + {clock("#FFFFFFFF", ambient_visible=True)} + {orb_slot()} + {"".join(ring_slot(i, a) for i, a in enumerate(ANGLES))} + {date_chip()} + + +''' +open(sys.argv[1], "w").write(xml) diff --git a/watch/watchface/src/main/AndroidManifest.xml b/watch/watchface/src/main/AndroidManifest.xml new file mode 100644 index 0000000..c2ea7a3 --- /dev/null +++ b/watch/watchface/src/main/AndroidManifest.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_baseball.png b/watch/watchface/src/main/res/drawable-nodpi/e_baseball.png new file mode 100644 index 0000000..f3d8487 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_baseball.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_bike.png b/watch/watchface/src/main/res/drawable-nodpi/e_bike.png new file mode 100644 index 0000000..0be9901 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_bike.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_camping.png b/watch/watchface/src/main/res/drawable-nodpi/e_camping.png new file mode 100644 index 0000000..f04d077 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_camping.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_carwash.png b/watch/watchface/src/main/res/drawable-nodpi/e_carwash.png new file mode 100644 index 0000000..5c21a5b Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_carwash.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_chestnut.png b/watch/watchface/src/main/res/drawable-nodpi/e_chestnut.png new file mode 100644 index 0000000..9c694e7 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_chestnut.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_chimaek.png b/watch/watchface/src/main/res/drawable-nodpi/e_chimaek.png new file mode 100644 index 0000000..a0c4f49 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_chimaek.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_delivery.png b/watch/watchface/src/main/res/drawable-nodpi/e_delivery.png new file mode 100644 index 0000000..504615e Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_delivery.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_dog.png b/watch/watchface/src/main/res/drawable-nodpi/e_dog.png new file mode 100644 index 0000000..6763a76 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_dog.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_garden.png b/watch/watchface/src/main/res/drawable-nodpi/e_garden.png new file mode 100644 index 0000000..dbde969 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_garden.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_glasses.png b/watch/watchface/src/main/res/drawable-nodpi/e_glasses.png new file mode 100644 index 0000000..b099365 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_glasses.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_hiking.png b/watch/watchface/src/main/res/drawable-nodpi/e_hiking.png new file mode 100644 index 0000000..5f92ba3 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_hiking.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_iced_hot.png b/watch/watchface/src/main/res/drawable-nodpi/e_iced_hot.png new file mode 100644 index 0000000..444fae2 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_iced_hot.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_jjamppong.png b/watch/watchface/src/main/res/drawable-nodpi/e_jjamppong.png new file mode 100644 index 0000000..0e05b74 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_jjamppong.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_laundry.png b/watch/watchface/src/main/res/drawable-nodpi/e_laundry.png new file mode 100644 index 0000000..804d560 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_laundry.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_makeup.png b/watch/watchface/src/main/res/drawable-nodpi/e_makeup.png new file mode 100644 index 0000000..6fe4d61 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_makeup.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_makgeolli.png b/watch/watchface/src/main/res/drawable-nodpi/e_makgeolli.png new file mode 100644 index 0000000..fa704b2 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_makgeolli.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_naengmyeon.png b/watch/watchface/src/main/res/drawable-nodpi/e_naengmyeon.png new file mode 100644 index 0000000..f112f43 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_naengmyeon.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_netflix.png b/watch/watchface/src/main/res/drawable-nodpi/e_netflix.png new file mode 100644 index 0000000..0f4de56 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_netflix.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_photo.png b/watch/watchface/src/main/res/drawable-nodpi/e_photo.png new file mode 100644 index 0000000..f1fe476 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_photo.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_picnic.png b/watch/watchface/src/main/res/drawable-nodpi/e_picnic.png new file mode 100644 index 0000000..28fb4b2 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_picnic.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_running.png b/watch/watchface/src/main/res/drawable-nodpi/e_running.png new file mode 100644 index 0000000..46a18e8 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_running.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_stars.png b/watch/watchface/src/main/res/drawable-nodpi/e_stars.png new file mode 100644 index 0000000..3e0be15 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_stars.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_study.png b/watch/watchface/src/main/res/drawable-nodpi/e_study.png new file mode 100644 index 0000000..e7803c1 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_study.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_taxi.png b/watch/watchface/src/main/res/drawable-nodpi/e_taxi.png new file mode 100644 index 0000000..268a464 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_taxi.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_vent.png b/watch/watchface/src/main/res/drawable-nodpi/e_vent.png new file mode 100644 index 0000000..c9e9c70 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_vent.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_walk.png b/watch/watchface/src/main/res/drawable-nodpi/e_walk.png new file mode 100644 index 0000000..d1fc03d Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_walk.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/e_yajang.png b/watch/watchface/src/main/res/drawable-nodpi/e_yajang.png new file mode 100644 index 0000000..8eafdd3 Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/e_yajang.png differ diff --git a/watch/watchface/src/main/res/drawable-nodpi/preview.png b/watch/watchface/src/main/res/drawable-nodpi/preview.png new file mode 100644 index 0000000..43b962b Binary files /dev/null and b/watch/watchface/src/main/res/drawable-nodpi/preview.png differ diff --git a/watch/watchface/src/main/res/font/bagel_fat_one.ttf b/watch/watchface/src/main/res/font/bagel_fat_one.ttf new file mode 100644 index 0000000..c512166 Binary files /dev/null and b/watch/watchface/src/main/res/font/bagel_fat_one.ttf differ diff --git a/watch/watchface/src/main/res/font/jua.ttf b/watch/watchface/src/main/res/font/jua.ttf new file mode 100644 index 0000000..b2ac41e Binary files /dev/null and b/watch/watchface/src/main/res/font/jua.ttf differ diff --git a/watch/watchface/src/main/res/raw/watchface.xml b/watch/watchface/src/main/res/raw/watchface.xml new file mode 100644 index 0000000..f10c9a2 --- /dev/null +++ b/watch/watchface/src/main/res/raw/watchface.xml @@ -0,0 +1,537 @@ + + + + + + + + + + = 5 && [HOUR_0_23] < 11]]> + = 11 && [HOUR_0_23] < 16]]> + = 16 && [HOUR_0_23] < 21]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + = 21]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/watch/watchface/src/main/res/values/strings.xml b/watch/watchface/src/main/res/values/strings.xml new file mode 100644 index 0000000..0bd6ab2 --- /dev/null +++ b/watch/watchface/src/main/res/values/strings.xml @@ -0,0 +1,7 @@ + + + 날씨각 + 오늘 1위 각 + 둘레 각 + 비·눈 + diff --git a/watch/watchface/src/main/res/xml/watch_face_info.xml b/watch/watchface/src/main/res/xml/watch_face_info.xml new file mode 100644 index 0000000..8d4e649 --- /dev/null +++ b/watch/watchface/src/main/res/xml/watch_face_info.xml @@ -0,0 +1,5 @@ + + + + +