Add initial status window
This commit is contained in:
+96
-13
@@ -1,3 +1,4 @@
|
||||
#include "main.h"
|
||||
#include "scheduler.h"
|
||||
#include "triangles.h"
|
||||
#include <pebble.h>
|
||||
@@ -5,10 +6,12 @@
|
||||
|
||||
// layer-age
|
||||
static Window *s_window;
|
||||
static Window *s_status_window;
|
||||
static Window *s_drop_window;
|
||||
static Layer *s_top_bar_layer;
|
||||
static Layer *s_bottom_bar_layer;
|
||||
static TextLayer *s_counter_txt_layer;
|
||||
static TextLayer *s_status_txt_layer;
|
||||
//// setter
|
||||
static BitmapLayer *s_clock_bmp_layer;
|
||||
static BitmapLayer *s_check_bmp_layer;
|
||||
@@ -78,7 +81,82 @@ static const char *s_options_function[3];
|
||||
static char *s_options_over[2];
|
||||
static char *s_options_under[2];
|
||||
|
||||
/////////////////////////////////
|
||||
////////////////////// STATUS //////////////////////
|
||||
|
||||
static void status_0_1_back_click_handler(void *recognizer, void *ctx) {
|
||||
s_highlight_pos = 0;
|
||||
window_stack_pop_all(true);
|
||||
push_setter_window();
|
||||
}
|
||||
|
||||
static void status_0_select_click_handler(void *recognizer, void *ctx) {
|
||||
window_stack_pop_all(true);
|
||||
}
|
||||
|
||||
static void status_2_select_click_handler(void *recognizer, void *ctx) {
|
||||
window_stack_pop(true);
|
||||
}
|
||||
|
||||
static void status_0_click_config_provider(void *ctx) {
|
||||
window_single_click_subscribe(BUTTON_ID_BACK, status_0_1_back_click_handler);
|
||||
window_single_click_subscribe(BUTTON_ID_SELECT, status_0_select_click_handler);
|
||||
}
|
||||
|
||||
static void status_1_click_config_provider(void *ctx) {
|
||||
window_single_click_subscribe(BUTTON_ID_BACK, status_0_1_back_click_handler);
|
||||
window_single_click_subscribe(BUTTON_ID_SELECT, status_0_1_back_click_handler);
|
||||
window_single_click_subscribe(BUTTON_ID_UP, status_0_1_back_click_handler);
|
||||
window_single_click_subscribe(BUTTON_ID_DOWN, status_0_1_back_click_handler);
|
||||
}
|
||||
|
||||
static void status_2_click_config_provider(void *ctx) {
|
||||
window_single_click_subscribe(BUTTON_ID_SELECT, status_2_select_click_handler);
|
||||
}
|
||||
|
||||
static void status_window_load(uint8_t reason) {
|
||||
Layer *window_layer = window_get_root_layer(s_status_window);
|
||||
|
||||
switch (reason) {
|
||||
case 0:
|
||||
tick_timer_service_unsubscribe();
|
||||
s_status_txt_layer = text_layer_create(GRect(0, 8, PBL_DISPLAY_WIDTH, PBL_DISPLAY_HEIGHT));
|
||||
text_layer_set_font(s_status_txt_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
|
||||
text_layer_set_text(s_status_txt_layer, "Alarm disarmed and re-set successfully.\n\nLast four times:\n1. 12:23\n2. 13:41\n3. 16:11\n4. 16:17");
|
||||
window_set_click_config_provider(s_status_window, status_0_click_config_provider);
|
||||
break;
|
||||
case 1:
|
||||
tick_timer_service_unsubscribe();
|
||||
s_status_txt_layer = text_layer_create(GRect(0, PBL_DISPLAY_HEIGHT / 2, PBL_DISPLAY_WIDTH, PBL_DISPLAY_HEIGHT));
|
||||
text_layer_set_font(s_status_txt_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28));
|
||||
text_layer_set_text(s_status_txt_layer, "Failed to set primary alarm.\nPress any button to return to alarm setter.");
|
||||
window_set_click_config_provider(s_status_window, status_1_click_config_provider);
|
||||
break;
|
||||
case 2:
|
||||
s_status_txt_layer = text_layer_create(GRect(0, (PBL_DISPLAY_HEIGHT / 2) - 37, PBL_DISPLAY_WIDTH, PBL_DISPLAY_HEIGHT));
|
||||
text_layer_set_font(s_status_txt_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28));
|
||||
text_layer_set_text(s_status_txt_layer, "Incorrect equation.\nTry again!");
|
||||
window_set_click_config_provider(s_status_window, status_2_click_config_provider);
|
||||
}
|
||||
text_layer_set_background_color(s_status_txt_layer, GColorClear);
|
||||
text_layer_set_text_alignment(s_status_txt_layer, GTextAlignmentCenter);
|
||||
layer_add_child(window_layer, text_layer_get_layer(s_status_txt_layer));
|
||||
}
|
||||
|
||||
static void status_window_unload() {
|
||||
text_layer_destroy(s_status_txt_layer);
|
||||
}
|
||||
|
||||
// reasons: 0 = confirmation, 1 = failure to set alarm, 2 = user sucks at math
|
||||
static void push_status_window(uint8_t reason) {
|
||||
s_status_window = window_create();
|
||||
window_set_window_handlers(
|
||||
s_status_window,
|
||||
(WindowHandlers){.unload = status_window_unload});
|
||||
status_window_load(reason);
|
||||
window_stack_push(s_status_window, true);
|
||||
}
|
||||
|
||||
////////////////////// MISC //////////////////////
|
||||
|
||||
static bool schedule_alarm(bool is_fallback) {
|
||||
time_t target;
|
||||
@@ -101,7 +179,8 @@ static bool schedule_alarm(bool is_fallback) {
|
||||
status = wakeup_schedule_simple_robust(target, SECONDS_PER_MINUTE, is_fallback);
|
||||
}
|
||||
if (status < 0) {
|
||||
return false; // TODO show failure window - user must acknowledge this window to close it
|
||||
push_status_window(1);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -452,10 +531,10 @@ static void alarm_window_load() {
|
||||
s_options_function[1] = s_cos;
|
||||
s_options_function[2] = s_tan;
|
||||
//// create drop window
|
||||
s_drop_window = window_create(); // TODO destroy on window unload?
|
||||
s_drop_window = window_create();
|
||||
window_set_window_handlers(
|
||||
s_drop_window,
|
||||
(WindowHandlers){.unload = drop_menu_window_unload});
|
||||
(WindowHandlers){.load = drop_menu_window_load, .unload = drop_menu_window_unload});
|
||||
|
||||
// stopwatch
|
||||
s_counter_txt_layer = text_layer_create(GRect(0, (s_small_top_bar_height / 2) - PBL_IF_ROUND_ELSE(6, 10), PBL_DISPLAY_WIDTH, s_small_top_bar_height));
|
||||
@@ -527,7 +606,6 @@ static void alarm_down_click_handler(void *recognizer, void *ctx) {
|
||||
}
|
||||
|
||||
static void alarm_select_click_handler(void *recognizer, void *ctx) {
|
||||
drop_menu_window_load(s_drop_window);
|
||||
window_stack_push(s_drop_window, true);
|
||||
}
|
||||
|
||||
@@ -535,14 +613,14 @@ static void alarm_select_hold_handler(void *recognizer, void *ctx) {
|
||||
// check solution
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
if (s_selected_indices[i] != s_solution_indices[i]) {
|
||||
return; // TODO pop-up telling the user they are wrong
|
||||
push_status_window(2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool success = schedule_alarm(false);
|
||||
if (success) {
|
||||
// TODO confirmation window
|
||||
window_stack_pop_all(true);
|
||||
push_status_window(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -702,6 +780,7 @@ static void setter_click_config_provider(void *ctx) {
|
||||
}
|
||||
|
||||
static void live_wakeup_handler_for_setter(WakeupId id, int32_t reason) {
|
||||
s_highlight_pos = 0;
|
||||
window_stack_pop_all(false);
|
||||
push_alarm_window();
|
||||
}
|
||||
@@ -770,6 +849,14 @@ static void setter_window_unload() {
|
||||
fonts_unload_custom_font(s_font_lecoish_big);
|
||||
}
|
||||
|
||||
static void push_setter_window() {
|
||||
window_set_window_handlers(
|
||||
s_window,
|
||||
(WindowHandlers){.load = setter_window_load, .unload = setter_window_unload});
|
||||
window_set_click_config_provider(s_window, setter_click_config_provider);
|
||||
window_stack_push(s_window, false);
|
||||
}
|
||||
|
||||
static void init() {
|
||||
s_window = window_create();
|
||||
s_font_lecoish_small = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_LECOISH_MONO_BOLD_20));
|
||||
@@ -784,11 +871,7 @@ static void init() {
|
||||
push_alarm_window();
|
||||
break;
|
||||
default:
|
||||
window_set_window_handlers(
|
||||
s_window,
|
||||
(WindowHandlers){.load = setter_window_load, .unload = setter_window_unload});
|
||||
window_set_click_config_provider(s_window, setter_click_config_provider);
|
||||
window_stack_push(s_window, false);
|
||||
push_setter_window();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
static void push_setter_window();
|
||||
Reference in New Issue
Block a user