/* * Handle an up or down button press and validate results */ static void up_down_handler(int8_t delta) { switch (current_field) { case F_FROM_HOUR: case F_TO_HOUR: alter_time(current_field, delta, 23, 0); break; case F_FROM_MINUTE: case F_TO_MINUTE: alter_time(current_field, 5 * delta, 55, 0); break; case F_SMART_ALARM: alter_time(current_field, 1, 1, 0); break; case F_DONE: if (values[F_DONE] == 1) hide_set_alarm(); else vibes_short_pulse(); break; } uint32_t from = to_mins(values[F_FROM_HOUR], values[F_FROM_MINUTE]); uint32_t to = to_mins(values[F_TO_HOUR], values[F_TO_MINUTE]); values[F_DONE] = (from <= to); write_values_to_fields(); }
/* * Build the settings window */ static void create_settings_window(void) { setting_window = window_create(); Layer *window_layer = window_get_root_layer(setting_window); GRect bounds = layer_get_bounds(window_layer); int16_t centre = bounds.size.w / 2; int16_t width = bounds.size.w; window_set_background_color(setting_window, SETTING_BACKGROUND_COLOR); is24hr = clock_is_24h_style(); // Get the resources we need large_font = fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD); small_font = fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD); // Set click provider window_set_click_config_provider(setting_window, (ClickConfigProvider) setting_click_config_provider); // from_layer from_layer = macro_text_layer_create(GRect(SA_ROW_1_X, SA_ROW_1_Y, SA_ROW_1_WIDTH, SA_HEIGHT), window_layer, NON_HIGHLIGHT_FG_COLOR, SETTING_BACKGROUND_COLOR, small_font, GTextAlignmentCenter); text_layer_set_text(from_layer, EARLIEST); // fields[FROM_HOUR] fields[F_FROM_HOUR] = macro_text_layer_create(GRect(is24hr ? SA_HOUR_LEFT_24 : SA_HOUR_LEFT_12, SA_ROW_2_Y, SA_WIDTH, SA_HEIGHT), window_layer, NON_HIGHLIGHT_FG_COLOR, NON_HIGHLIGHT_BG_COLOR, large_font, GTextAlignmentCenter); // fields[FROM_MINUTE] fields[F_FROM_MINUTE] = macro_text_layer_create(GRect(is24hr ? SA_MIN_LEFT_24 : SA_MIN_LEFT_12, SA_ROW_2_Y, SA_WIDTH, SA_HEIGHT), window_layer, NON_HIGHLIGHT_FG_COLOR, NON_HIGHLIGHT_BG_COLOR, large_font, GTextAlignmentCenter); // fields[FROM_AMPM] if (!is24hr) { fields[F_FROM_AMPM] = macro_text_layer_create(GRect(SA_AMPM_LEFT, SA_ROW_2_Y, SA_WIDTH, SA_HEIGHT), window_layer, NON_HIGHLIGHT_FG_COLOR, NON_HIGHLIGHT_BG_COLOR, large_font, GTextAlignmentCenter); } // to_layer to_layer = macro_text_layer_create(GRect(SA_ROW_3_X, SA_ROW_3_Y, SA_ROW_3_WIDTH, SA_HEIGHT), window_layer, NON_HIGHLIGHT_FG_COLOR, SETTING_BACKGROUND_COLOR, small_font, GTextAlignmentCenter); text_layer_set_text(to_layer, LATEST); // fields[TO_HOUR] fields[F_TO_HOUR] = macro_text_layer_create(GRect(is24hr ? SA_HOUR_LEFT_24 : SA_HOUR_LEFT_12, SA_ROW_4_Y, SA_WIDTH, SA_HEIGHT), window_layer, NON_HIGHLIGHT_FG_COLOR, NON_HIGHLIGHT_BG_COLOR, large_font, GTextAlignmentCenter); // fields[TO_MINUTE] fields[F_TO_MINUTE] = macro_text_layer_create(GRect(is24hr ? SA_MIN_LEFT_24 : SA_MIN_LEFT_12, SA_ROW_4_Y, SA_WIDTH, SA_HEIGHT), window_layer, NON_HIGHLIGHT_FG_COLOR, NON_HIGHLIGHT_BG_COLOR, large_font, GTextAlignmentCenter); // fields[TO_AMPM] if (!is24hr) { fields[F_TO_AMPM] = macro_text_layer_create(GRect(SA_AMPM_LEFT, SA_ROW_4_Y, SA_WIDTH, SA_HEIGHT), window_layer, NON_HIGHLIGHT_FG_COLOR, NON_HIGHLIGHT_BG_COLOR, large_font, GTextAlignmentCenter); } current_field = F_FROM_HOUR; set_values(); write_values_to_fields(); highlight_field(current_field, true); }
/* * Handle an up or down button press */ static void up_down_handler(int8_t delta) { switch (current_field) { case F_FROM_HOUR: case F_TO_HOUR: alter_time(current_field, delta, is24hr ? 23 : 12, is24hr ? 0 : 1); break; case F_FROM_MINUTE: case F_TO_MINUTE: alter_time(current_field, 5 * delta, 55, 0); break; case F_FROM_AMPM: case F_TO_AMPM: alter_time(current_field, 1, 1, 0); break; } write_values_to_fields(); }
/* * Build the settings window */ static void create_settings_window(void) { setting_window = window_create(); Layer *window_layer = window_get_root_layer(setting_window); window_set_background_color(setting_window, SETTING_BACKGROUND_COLOR); // Get the resources we need up_button_res = gbitmap_create_with_resource(RESOURCE_ID_PICK_UP); next_button_res = gbitmap_create_with_resource(RESOURCE_ID_PICK_NEXT); down_button_res = gbitmap_create_with_resource(RESOURCE_ID_PICK_DOWN); tick_button_res = gbitmap_create_with_resource(RESOURCE_ID_PICK_TICK); small_font = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD); large_font = fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD); // button_layer button_layer = action_bar_layer_create(); action_bar_layer_add_to_window(button_layer, setting_window); action_bar_layer_set_background_color(button_layer, ACTION_BAR_BACKGROUND_COLOR); action_bar_layer_set_icon(button_layer, BUTTON_ID_UP, up_button_res); action_bar_layer_set_icon(button_layer, BUTTON_ID_SELECT, next_button_res); action_bar_layer_set_icon(button_layer, BUTTON_ID_DOWN, down_button_res); #ifdef PBL_PLATFORM_BASALT action_bar_layer_set_icon_press_animation(button_layer, BUTTON_ID_UP, ActionBarLayerIconPressAnimationMoveUp); action_bar_layer_set_icon_press_animation(button_layer, BUTTON_ID_SELECT, ActionBarLayerIconPressAnimationMoveRight); action_bar_layer_set_icon_press_animation(button_layer, BUTTON_ID_DOWN, ActionBarLayerIconPressAnimationMoveDown); #endif layer_add_child(window_layer, (Layer *) button_layer); action_bar_layer_set_click_config_provider(button_layer, setting_click_config_provider); // title_layer title_layer = macro_text_layer_create(GRect(SETTING_TITLE_LEFT, 6, 90, SETTING_SMALL_FONT_HEIGHT), window_layer, NON_HIGHLIGHT_FG_COLOR, NON_HIGHLIGHT_BG_COLOR, small_font, GTextAlignmentLeft); text_layer_set_text(title_layer, SMART_ALARM); // from_layer from_layer = macro_text_layer_create(GRect(SETTING_TITLE_LEFT, 30, 55, SETTING_SMALL_FONT_HEIGHT), window_layer, NON_HIGHLIGHT_FG_COLOR, NON_HIGHLIGHT_BG_COLOR, small_font, GTextAlignmentLeft); text_layer_set_text(from_layer, EARLIEST); // fields[FROM_HOUR] fields[F_FROM_HOUR] = macro_text_layer_create(GRect(20, SETTING_FROM_TOP, SETTING_TIME_WIDTH, SETTING_BIG_FONT_HEIGHT), window_layer, NON_HIGHLIGHT_FG_COLOR, NON_HIGHLIGHT_BG_COLOR, large_font, GTextAlignmentCenter); // from_colon_layer from_colon_layer = macro_text_layer_create(GRect(43, SETTING_FROM_TOP, 13, SETTING_BIG_FONT_HEIGHT), window_layer, NON_HIGHLIGHT_FG_COLOR, NON_HIGHLIGHT_BG_COLOR, large_font, GTextAlignmentCenter); text_layer_set_text(from_colon_layer, COLON); // fields[FROM_MINUTE] fields[F_FROM_MINUTE] = macro_text_layer_create(GRect(52, SETTING_FROM_TOP, SETTING_TIME_WIDTH, SETTING_BIG_FONT_HEIGHT), window_layer, NON_HIGHLIGHT_FG_COLOR, NON_HIGHLIGHT_BG_COLOR, large_font, GTextAlignmentCenter); // to_layer to_layer = macro_text_layer_create(GRect(SETTING_TITLE_LEFT, 81, 48, SETTING_SMALL_FONT_HEIGHT), window_layer, NON_HIGHLIGHT_FG_COLOR, NON_HIGHLIGHT_BG_COLOR, small_font, GTextAlignmentLeft); text_layer_set_text(to_layer, LATEST); // fields[TO_HOUR] fields[F_TO_HOUR] = macro_text_layer_create(GRect(20, SETTING_TO_TOP, SETTING_TIME_WIDTH, SETTING_BIG_FONT_HEIGHT), window_layer, NON_HIGHLIGHT_FG_COLOR, NON_HIGHLIGHT_BG_COLOR, large_font, GTextAlignmentCenter); // to_color_layer to_color_layer = macro_text_layer_create(GRect(43, SETTING_TO_TOP, 13, SETTING_BIG_FONT_HEIGHT), window_layer, NON_HIGHLIGHT_FG_COLOR, NON_HIGHLIGHT_BG_COLOR, large_font, GTextAlignmentCenter); text_layer_set_text(to_color_layer, COLON); // fields[TO_MINUTE] fields[F_TO_MINUTE] = macro_text_layer_create(GRect(52, SETTING_TO_TOP, SETTING_TIME_WIDTH, SETTING_BIG_FONT_HEIGHT), window_layer, NON_HIGHLIGHT_FG_COLOR, NON_HIGHLIGHT_BG_COLOR, large_font, GTextAlignmentCenter); // fields[SMART_ALARM] fields[F_SMART_ALARM] = macro_text_layer_create(GRect(SA_LEFT, SA_TOP, 25, SETTING_BIG_FONT_HEIGHT), window_layer, NON_HIGHLIGHT_FG_COLOR, NON_HIGHLIGHT_BG_COLOR, large_font, GTextAlignmentCenter); // fields[DONE] fields[F_DONE] = macro_text_layer_create(GRect(DONE_LEFT, DONE_TOP, 45, SETTING_BIG_FONT_HEIGHT), window_layer, NON_HIGHLIGHT_FG_COLOR, NON_HIGHLIGHT_BG_COLOR, large_font, GTextAlignmentCenter); current_field = F_SMART_ALARM; set_values(); write_values_to_fields(); highlight_field(current_field, true); }