// We have to poll the quiet_time_is_active() state from time to // time because Pebble doesn't provide a callback handler for this. bool poll_quiet_time_state() { bool new_quiet_time_state = quiet_time_is_active(); if (quiet_time_state == new_quiet_time_state) { // No change. return quiet_time_state; } quiet_time_state = new_quiet_time_state; qapp_log(APP_LOG_LEVEL_INFO, __FILE__, __LINE__, "quiet_time changed to %d", quiet_time_state); if (config.bluetooth_indicator != IM_off) { invalidate_clock_face(); } return quiet_time_state; }
void red_line_layer_update_callback(Layer *RedLineLayer, GContext* ctx) { if (quiet_time_is_active()) { QuietTimeColor = GColorYellow; } else { QuietTimeColor = GColorRed; } #if PBL_COLOR graphics_context_set_fill_color(ctx, QuietTimeColor); #else //B&W graphics_context_set_fill_color(ctx, TextColorHold); #endif graphics_fill_rect(ctx, layer_get_bounds(RedLineLayer), 0, GCornerNone); }
void ui_layout() { int top = MARGINTOP; if ((is_sleeping && config.auto_sleep_mode) || (config.low_power_quiet_mode && quiet_time_is_active())) { text_layer_move(ui.layers.time, 0, top + (PHEIGHT - top) * 0.20); text_layer_move(ui.layers.date, 0, top + (PHEIGHT - top) * 0.50); text_layer_hide(ui.layers.status_bar); text_layer_hide(ui.layers.status_bar1); text_layer_hide(ui.layers.status_bar2); text_layer_hide(ui.layers.status_bar3); layer_hide(ui.layers.battery); text_layer_hide(ui.layers.month); text_layer_hide(ui.layers.info_box_left); text_layer_hide(ui.layers.info_box_right); } else { text_layer_show(ui.layers.date); text_layer_show(ui.layers.month); text_layer_show(ui.layers.info_box_left); text_layer_show(ui.layers.info_box_right); if (config.show_status_bar == 1) { top = MARGINTOP_WITH_STATUS_BAR; } if (config.layout == 1) { //Reverse Classic layout if (config.hide_battery == 1) { text_layer_move(ui.layers.time, 0, top + (PHEIGHT - top) * 0.62); text_layer_move(ui.layers.date, 0, top + (PHEIGHT - top) * 0.42); } else { text_layer_move(ui.layers.time, 0, top + (PHEIGHT - top) * 0.64); text_layer_move(ui.layers.date, 0, top + (PHEIGHT - top) * 0.40); } layer_move(ui.layers.battery, 0, top + (PHEIGHT - top) * 0.44); text_layer_move(ui.layers.month, 0, top + (PHEIGHT - top) * 0.28); text_layer_move(ui.layers.info_box_left, INFO_MARGIN, top + (PHEIGHT - top) * 0.05); text_layer_move(ui.layers.info_box_right, HALFPWIDTH + 1, top + (PHEIGHT - top) * 0.05); } else { //Classic layout if (config.hide_battery == 1) { text_layer_move(ui.layers.time, 0, top + (PHEIGHT - top) * 0.02); text_layer_move(ui.layers.date, 0, top + (PHEIGHT - top) * 0.36); } else { text_layer_move(ui.layers.time, 0, top); text_layer_move(ui.layers.date, 0, top + (PHEIGHT - top) * 0.38); } layer_move(ui.layers.battery, 0, top + (PHEIGHT - top) * 0.18); text_layer_move(ui.layers.month, 0, top + (PHEIGHT - top) * 0.59); text_layer_move(ui.layers.info_box_left, INFO_MARGIN, top + (PHEIGHT - top) * 0.74); text_layer_move(ui.layers.info_box_right, HALFPWIDTH + 1, top + (PHEIGHT - top) * 0.74); } if (config.hide_battery == 1) { layer_hide(ui.layers.battery); } else { layer_show(ui.layers.battery); } if (config.show_status_bar == 1) { text_layer_show(ui.layers.status_bar); text_layer_show(ui.layers.status_bar2); #ifdef PBL_ROUND text_layer_hide(ui.layers.status_bar1); text_layer_hide(ui.layers.status_bar3); #else text_layer_show(ui.layers.status_bar1); text_layer_show(ui.layers.status_bar3); #endif } else { text_layer_hide(ui.layers.status_bar); text_layer_hide(ui.layers.status_bar1); text_layer_hide(ui.layers.status_bar2); text_layer_hide(ui.layers.status_bar3); } if (is_obstructed) { text_layer_hide(ui.layers.info_box_left); text_layer_hide(ui.layers.info_box_right); text_layer_hide(ui.layers.month); } else { text_layer_show(ui.layers.info_box_left); text_layer_show(ui.layers.info_box_right); text_layer_show(ui.layers.month); } } }
//********************************** Handle Init ************************** void handle_init(void) { if (quiet_time_is_active()) { QuietTimeColor = GColorYellow; } else { QuietTimeColor = GColorRed; } GColor BGCOLOR = COLOR_FALLBACK(GColorDukeBlue, GColorBlack); BGColorHold = BGCOLOR; GColor TEXTCOLOR = COLOR_FALLBACK(GColorWhite, GColorWhite); TextColorHold = TEXTCOLOR; window = window_create(); window_set_background_color(window, BGCOLOR); window_stack_push(window, true /* Animated */); fontHelvNewLight20 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_HELV_NEW_LIGHT_20)); fontRobotoCondensed20 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_20)); fontRobotoCondensed21 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_21)); fontRobotoBoldSubset37 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_37)); fontRobotoBoldSubset49 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_BOLD_SUBSET_49)); Layer *window_layer = window_get_root_layer(window); // Register callbacks app_message_register_inbox_received(inbox_received_callback); app_message_register_inbox_dropped(inbox_dropped_callback); app_message_register_outbox_failed(outbox_failed_callback); app_message_register_outbox_sent(outbox_sent_callback); // Open AppMessage app_message_open(128, 128); //degrees text_degrees_layer = text_layer_create(GRect(30, 1, 60, 200)); text_layer_set_text_alignment(text_degrees_layer, GTextAlignmentCenter); text_layer_set_text(text_degrees_layer, degreesstr); text_layer_set_font(text_degrees_layer, fontRobotoCondensed20); text_layer_set_background_color(text_degrees_layer, BGCOLOR); text_layer_set_text_color(text_degrees_layer, TEXTCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_degrees_layer)); //degrees inside text_degrees_inside_layer = text_layer_create(GRect(85, 2, 55, 26)); text_layer_set_text_alignment(text_degrees_inside_layer, GTextAlignmentRight); text_layer_set_text(text_degrees_inside_layer, degreesstr); text_layer_set_font(text_degrees_inside_layer, fontRobotoCondensed20); text_layer_set_background_color(text_degrees_inside_layer, BGCOLOR); text_layer_set_text_color(text_degrees_inside_layer, TEXTCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_degrees_inside_layer)); // WA1OUI text_wa1oui_layer = text_layer_create(GRect(1,25, 144, 148)); text_layer_set_text_alignment(text_wa1oui_layer, GTextAlignmentCenter); text_layer_set_text(text_wa1oui_layer, "WA1OUI"); text_layer_set_font(text_wa1oui_layer, fontRobotoBoldSubset37); text_layer_set_text_color(text_wa1oui_layer, TEXTCOLOR); text_layer_set_background_color(text_wa1oui_layer, BGCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_wa1oui_layer)); // Dayname text_dayname_layer = text_layer_create(GRect(1, 65, 35, 168-65)); text_layer_set_text_alignment(text_dayname_layer, GTextAlignmentLeft); text_layer_set_font(text_dayname_layer, fontRobotoCondensed20); text_layer_set_text_color(text_dayname_layer, TEXTCOLOR); text_layer_set_background_color(text_dayname_layer, BGCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_dayname_layer)); // wind text_wind_layer = text_layer_create(GRect(37, 65, 60, 168-65)); text_layer_set_text_alignment(text_wind_layer, GTextAlignmentCenter); text_layer_set_font(text_wind_layer, fontRobotoCondensed20); text_layer_set_text_color(text_wind_layer, TEXTCOLOR); text_layer_set_background_color(text_wind_layer, BGCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_wind_layer)); // Rain text_rain_layer = text_layer_create(GRect(95, 65, 49, 168-65)); text_layer_set_text_alignment(text_rain_layer, GTextAlignmentRight); text_layer_set_font(text_rain_layer, fontRobotoCondensed21); text_layer_set_text_color(text_rain_layer, TEXTCOLOR); text_layer_set_background_color(text_rain_layer, BGCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_rain_layer)); // Date text_date_layer = text_layer_create(GRect(8, 88, 144-8, 168-88)); text_layer_set_text_alignment(text_date_layer, GTextAlignmentCenter); text_layer_set_font(text_date_layer, fontRobotoCondensed21); text_layer_set_text_color(text_date_layer, TEXTCOLOR); text_layer_set_background_color(text_date_layer, BGCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_date_layer)); // Time of Day text_time_layer = text_layer_create(GRect(7, 116, 144-7, 168-116)); text_layer_set_text_alignment(text_time_layer, GTextAlignmentCenter); text_layer_set_font(text_time_layer, fontRobotoBoldSubset49); text_layer_set_text_color(text_time_layer, TEXTCOLOR); text_layer_set_background_color(text_time_layer, BGCOLOR); layer_add_child(window_layer, text_layer_get_layer(text_time_layer)); // Red Line GRect red_line_frame = GRect(10, 28, 124, 2); RedLineLayer = layer_create(red_line_frame); layer_set_update_proc(RedLineLayer, red_line_layer_update_callback); layer_add_child(window_layer, RedLineLayer); // Battery Line GRect line_frame = GRect(22, 118, 104, 6); LineLayer = layer_create(line_frame); layer_set_update_proc(LineLayer, line_layer_update_callback); layer_add_child(window_layer, LineLayer); tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); //Bluetooth Logo Setup area GRect BTArea = GRect(1, 5, 20, 20); BTLayer1 = layer_create(BTArea); layer_add_child(window_layer, BTLayer1); layer_set_update_proc(BTLayer1, BTLine_update_callback); bluetooth_connection_service_subscribe(&handle_bluetooth); handle_bluetooth(bluetooth_connection_service_peek()); handle_battery(battery_state_service_peek()); //app focus service subscribe app_focus_service_subscribe(&handle_appfocus); // Ensures time is displayed immediately (will break if NULL tick event accessed). // (This is why it's a good idea to have a separate routine to do the update itself.) time_t now = time(NULL); struct tm *current_time = localtime(&now); handle_tick(current_time, SECOND_UNIT); }
static void received_config(DictionaryIterator *received) { loadingMode = false; uint8_t* data = dict_find(received, 2)->value->data; uint16_t supportedVersion = (data[8] << 8) | (data[9]); if (supportedVersion > PROTOCOL_VERSION) { show_old_watchapp_error(); return; } else if (supportedVersion < PROTOCOL_VERSION) { show_old_android_error(); return; } config_timeout = (data[3] << 8) | (data[4]); config_dontClose = (data[7] & 0x02) != 0; config_showActive = (data[7] & 0x04) != 0; main_noMenu = (data[7] & 0x08) != 0; config_lightScreen = (data[7] & 0x10) != 0; config_dontVibrateWhenCharging = (data[7] & 0x20) != 0; config_disableNotifications = (data[7] & 0x80) != 0; config_whiteText = (data[7] & 0x740) != 0; config_disableVibration = (data[7] & 0x01) != 0; config_displayScrollShadow = (data[13] & 0x01) != 0; config_scrollByPage = PBL_IF_ROUND_ELSE(true, (data[13] & 0x02) != 0); config_disconnectedNotification = (data[13] & 0x04) != 0; config_gestures = (data[13] & 0x08) != 0; config_periodicTimeout = (data[11] << 8) | (data[12]); config_lightTimeout = data[5]; config_periodicVibrationPatternSize = data[14]; config_periodicVibrationTotalDuration = 0; config_periodicVibrationPattern = malloc(config_periodicVibrationPatternSize / 2 * sizeof(uint32_t)); for (int i = 0; i < config_periodicVibrationPatternSize; i+= 2) { config_periodicVibrationPattern[i / 2] = data[15 + i] | (data[16 + i] << 8); config_periodicVibrationTotalDuration += config_periodicVibrationPattern[i / 2]; } #if PBL_COLOR config_skew_background_image_colors = (data[13] & 0x10) != 0; #endif loadingMode = false; gotConfig = true; bool respectQuietTime = (data[13] & 0x20) != 0; if (respectQuietTime && quiet_time_is_active()) { AppLaunchReason launchReason = launch_reason(); if (launchReason == APP_LAUNCH_PHONE) { // App was launched by phone, but quiet time is active. Lets bail out. closingMode = true; rejectNotifications = true; gotConfig = false; } } if (rejectNotifications) { show_quitting(); } else if (!main_noMenu) { show_menu(); } }