Add a pretty slick startup animation

This commit is contained in:
2026-04-26 13:53:06 -04:00
parent aba16a8b5f
commit 3a463b591f

View File

@@ -17,10 +17,19 @@ static Layer *s_pin_icon_layer;
static GDrawCommandImage *s_sleep_icon;
static GDrawCommandImage *s_pin_icon;
// declare animation statics
static GRect s_sleep_bar_start = GRect(0, 0, PBL_DISPLAY_WIDTH, PBL_DISPLAY_HEIGHT);
static GRect s_sleep_icon_start = GRect((PBL_DISPLAY_HEIGHT / 2) - 13, (PBL_DISPLAY_HEIGHT / 2) - 12, 25, 25);
// declare time tracking statics
static time_t s_sleep_timestamp;
static bool s_sleep_data_accessible;
static void load_complete_animation_handler(Animation *animation, bool finished, void *context) {
layer_set_hidden(text_layer_get_layer(s_sleep_time_layer), false);
animation_destroy(animation);
}
static void send_sleep_time_to_pkjs() {
DictionaryIterator *out;
AppMessageResult result = app_message_outbox_begin(&out);
@@ -39,13 +48,13 @@ static void send_sleep_time_to_pkjs() {
static void inbox_received_handler(DictionaryIterator *iter, void *context) {
Tuple *ready_tuple = dict_find(iter, MESSAGE_KEY_PKJS_READY);
if (ready_tuple) {
APP_LOG(APP_LOG_LEVEL_INFO, "Received PKJS_READY, calling PKJS...");
// APP_LOG(APP_LOG_LEVEL_INFO, "Received PKJS_READY, calling PKJS...");
send_sleep_time_to_pkjs();
}
Tuple *clay_tuple = dict_find(iter, MESSAGE_KEY_CLAY_API_IS_JELLYFIN);
if (clay_tuple) {
APP_LOG(APP_LOG_LEVEL_INFO, "Received CLAY_API_IS_JELLYFIN, updating UI...");
// APP_LOG(APP_LOG_LEVEL_INFO, "Received CLAY_API_IS_JELLYFIN, updating UI...");
bool is_jellyfin = clay_tuple->value->int32 == 1;
if (is_jellyfin) {
persist_write_int(0, 1);
@@ -72,8 +81,21 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
Tuple *watched_tuple = dict_find(iter, MESSAGE_KEY_PKJS_LAST_WATCHED);
if (watched_tuple) {
APP_LOG(APP_LOG_LEVEL_INFO, "Received PKJS_LAST_WATCHED, displaying...");
// APP_LOG(APP_LOG_LEVEL_INFO, "Received PKJS_LAST_WATCHED, displaying...");
text_layer_set_text(s_last_watched_layer, watched_tuple->value->cstring);
#if PBL_DISPLAY_WIDTH >= 200
PropertyAnimation *sleep_bar_prop = property_animation_create_layer_frame(s_sleep_bar_layer, &s_sleep_bar_start, &GRect(0, -PBL_DISPLAY_HEIGHT + PBL_IF_ROUND_ELSE(53, 31), PBL_DISPLAY_WIDTH, PBL_DISPLAY_HEIGHT));
#else
PropertyAnimation *sleep_bar_prop = property_animation_create_layer_frame(s_sleep_bar_layer, &s_sleep_bar_start, &GRect(0, -PBL_DISPLAY_HEIGHT + PBL_IF_ROUND_ELSE(49, 31), PBL_DISPLAY_WIDTH, PBL_DISPLAY_HEIGHT));
#endif
Animation *sleep_bar_anim = property_animation_get_animation(sleep_bar_prop);
animation_set_duration(sleep_bar_anim, 512);
PropertyAnimation *sleep_icon_prop = property_animation_create_layer_frame(s_sleep_icon_layer, &s_sleep_icon_start, &GRect(PBL_IF_ROUND_ELSE((PBL_DISPLAY_WIDTH / 2) - 13, 4), 4, 25, 25));
Animation *sleep_icon_anim = property_animation_get_animation(sleep_icon_prop);
animation_set_duration(sleep_icon_anim, 512);
Animation *load_spawn_anim = animation_spawn_create(sleep_bar_anim, sleep_icon_anim, NULL);
animation_set_handlers(load_spawn_anim, (AnimationHandlers){.stopped = load_complete_animation_handler}, NULL);
animation_schedule(load_spawn_anim);
}
}
@@ -109,8 +131,9 @@ static void pin_icon_update_proc(Layer *layer, GContext *ctx) {
}
static void main_window_load(Window *window) {
// sleep icon
s_sleep_icon_layer = layer_create(GRect(PBL_IF_ROUND_ELSE((PBL_DISPLAY_WIDTH / 2) - 13, 4), 4, 25, 25));
// sleep bar and icon
s_sleep_bar_layer = layer_create(s_sleep_bar_start);
s_sleep_icon_layer = layer_create(s_sleep_icon_start);
layer_set_update_proc(s_sleep_icon_layer, sleep_icon_update_proc);
// pin icon
@@ -118,16 +141,14 @@ static void main_window_load(Window *window) {
layer_set_update_proc(s_pin_icon_layer, pin_icon_update_proc);
#if PBL_DISPLAY_WIDTH >= 200
s_sleep_bar_layer = layer_create(GRect(0, 0, PBL_DISPLAY_WIDTH, PBL_IF_ROUND_ELSE(53, 31)));
s_sleep_time_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(21, -2), PBL_DISPLAY_WIDTH, 30));
s_last_watched_layer = text_layer_create(GRect(PBL_IF_ROUND_ELSE(28, 4), PBL_DISPLAY_HEIGHT / 2 - 20, PBL_DISPLAY_WIDTH - PBL_IF_ROUND_ELSE(56, 4), PBL_DISPLAY_HEIGHT));
s_last_watched_layer = text_layer_create(GRect(PBL_IF_ROUND_ELSE(28, 4), PBL_DISPLAY_HEIGHT / 2 - 20, PBL_DISPLAY_WIDTH - PBL_IF_ROUND_ELSE(56, 29), PBL_DISPLAY_HEIGHT));
text_layer_set_font(s_sleep_time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
text_layer_set_text_alignment(s_sleep_time_layer, GTextAlignmentCenter);
text_layer_set_font(s_last_watched_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28));
#else
s_sleep_bar_layer = layer_create(GRect(0, 0, PBL_DISPLAY_WIDTH, PBL_IF_ROUND_ELSE(49, 31)));
s_sleep_time_layer = text_layer_create(GRect(PBL_IF_ROUND_ELSE(0, 31), PBL_IF_ROUND_ELSE(24, 6), PBL_DISPLAY_WIDTH, 30));
s_last_watched_layer = text_layer_create(GRect(PBL_IF_ROUND_ELSE(28, 4), PBL_DISPLAY_HEIGHT / 2 - 17, PBL_DISPLAY_WIDTH - PBL_IF_ROUND_ELSE(56, 4), PBL_DISPLAY_HEIGHT));
s_last_watched_layer = text_layer_create(GRect(PBL_IF_ROUND_ELSE(28, 4), PBL_DISPLAY_HEIGHT / 2 - 17, PBL_DISPLAY_WIDTH - PBL_IF_ROUND_ELSE(56, 29), PBL_DISPLAY_HEIGHT));
text_layer_set_font(s_sleep_time_layer, fonts_get_system_font(PBL_IF_ROUND_ELSE(FONT_KEY_GOTHIC_18_BOLD, FONT_KEY_GOTHIC_14_BOLD)));
text_layer_set_text_alignment(s_sleep_time_layer, PBL_IF_ROUND_ELSE(GTextAlignmentCenter, GTextAlignmentLeft));
text_layer_set_font(s_last_watched_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
@@ -144,6 +165,7 @@ static void main_window_load(Window *window) {
} else {
text_layer_set_text(s_sleep_time_layer, "No sleep last night");
}
layer_set_hidden(text_layer_get_layer(s_sleep_time_layer), true);
// misc. properties
layer_set_update_proc(s_sleep_bar_layer, sleep_bar_update_proc);
@@ -167,10 +189,10 @@ static void main_window_load(Window *window) {
layer_add_child(window_layer, s_button_bar_layer);
#endif
layer_add_child(window_layer, s_pin_icon_layer);
layer_add_child(window_layer, text_layer_get_layer(s_last_watched_layer));
layer_add_child(window_layer, s_sleep_bar_layer);
layer_add_child(window_layer, s_sleep_icon_layer);
layer_add_child(window_layer, text_layer_get_layer(s_sleep_time_layer));
layer_add_child(window_layer, text_layer_get_layer(s_last_watched_layer));
}
static void main_window_unload(Window *window) {