void tap_handler(AccelAxisType axis, int32_t direction){ time_t now = time(NULL); if(layer_get_hidden(text_layer_get_layer(date_layer)) == 0) { layer_set_hidden(text_layer_get_layer(date_layer), true); layer_set_hidden(text_layer_get_layer(game_layer), false); } else if(layer_get_hidden(text_layer_get_layer(date_layer)) == 1) { layer_set_hidden(text_layer_get_layer(game_layer), true); layer_set_hidden(text_layer_get_layer(date_layer), false); } APP_LOG(APP_LOG_LEVEL_DEBUG, "Tap Handler"); }
void handle_battery(BatteryChargeState charge_state) { #if DEBUG //strftime(debug_buffer, DEBUG_BUFFER_BYTES, "%d.%m.%Y %H:%M:%S", now); snprintf(debug_buffer, DEBUG_BUFFER_BYTES, "%s%d%%", charge_state.is_charging ? "+" : "", charge_state.charge_percent); text_layer_set_text(debug_layer, debug_buffer); #endif #if SCREENSHOT bitmap_layer_set_bitmap(battery_layer, battery_images[1]); bool showSeconds = seconds_mode != SECONDS_MODE_NEVER; bool showBattery = battery_mode != BATTERY_MODE_NEVER; bool showDate = date_mode != DATE_MODE_NEVER; #else bitmap_layer_set_bitmap(battery_layer, battery_images[ (charge_state.is_charging ? 11 : 0) + min(charge_state.charge_percent / 9, 10)]); // 90% is max bool battery_is_low = charge_state.charge_percent <= 10; bool showSeconds = seconds_mode == SECONDS_MODE_ALWAYS || (seconds_mode == SECONDS_MODE_IFNOTLOW && (!battery_is_low || charge_state.is_charging)); bool showBattery = battery_mode == BATTERY_MODE_ALWAYS || (battery_mode == BATTERY_MODE_IF_LOW && battery_is_low) || charge_state.is_charging; bool showDate = date_mode != DATE_MODE_NEVER; #endif if (hide_seconds != !showSeconds) { hide_seconds = !showSeconds; tick_timer_service_unsubscribe(); tick_timer_service_subscribe(hide_seconds ? MINUTE_UNIT : SECOND_UNIT, &handle_tick); } layer_set_hidden(bitmap_layer_get_layer(battery_layer), !showBattery); if (layer_get_hidden(date_layer) != !showDate) { layer_set_hidden(date_layer, !showDate); layer_set_frame(background_layer, GRect(0, showDate ? 0 : 12, 144, 144)); } }
void draw_layer(Layer *layer, GContext *gctxt) { if (!layer_get_hidden(layer)) { graphics_context_set_fill_color(gctxt, negativeBackgroundColour); GRect rect = layer_get_bounds(layer); graphics_fill_rect(gctxt, rect, 5, GCornersAll); } }
static void update_seconds(struct tm *tick_time) { if(blink) { layer_set_hidden(bitmap_layer_get_layer(separator_layer), tick_time->tm_sec%2); } else { if(layer_get_hidden(bitmap_layer_get_layer(separator_layer))) { layer_set_hidden(bitmap_layer_get_layer(separator_layer), false); } } }
static void update_battery_status(BatteryChargeState charge_state) { for (int i=0; i<20; i++) { // check each pellet (5%) bool pelletShouldBeHidden = charge_state.charge_percent < i*5; bool isHidden = layer_get_hidden((Layer*)s_battery_pellet[i]); if (pelletShouldBeHidden != isHidden) { layer_set_hidden((Layer*)s_battery_pellet[i], pelletShouldBeHidden); } } }
static void update_seconds(struct tm *tick_time) { if(blink) { layer_set_hidden(bitmap_layer_get_layer(layer_batt_img), tick_time->tm_sec%5); } else { if(layer_get_hidden(bitmap_layer_get_layer(layer_batt_img))) { layer_set_hidden(bitmap_layer_get_layer(layer_batt_img), false); } } }
void hide_seconds(myTimeLayer *mtl) { Layer *l = text_layer_get_layer(mtl->exp_digits->tl_obj); if(!layer_get_hidden(l)) { layer_set_hidden(l,true); l = text_layer_get_layer(mtl->big_digits->tl_obj); GRect bounds = layer_get_frame(l); bounds.origin.x += bounds.size.w / 4; layer_set_frame(l,bounds); } }
static void tap_handler(AccelAxisType axis, int32_t direction) { bool summary = false; bool day_summary = true; if (axis == ACCEL_AXIS_Y) { if (layer_get_hidden(s_weather_day_summary_layer) == true) { summary = true; day_summary = false; } layer_set_hidden(text_layer_get_layer(s_weather_summary_layer), summary); layer_set_hidden(s_weather_day_summary_layer, day_summary); } }
static void select_callback(struct MenuLayer *s_menu_layer, MenuIndex *cell_index, void *callback_context) { APP_LOG(APP_LOG_LEVEL_DEBUG, "listSize is %d",listSize); // If we were displaying s_error_text_layer, remove it and return if (!layer_get_hidden(text_layer_get_layer(s_error_text_layer))) { layer_set_hidden(text_layer_get_layer(s_error_text_layer), true); return; } if (listSize == 0) { layer_set_hidden(text_layer_get_layer(s_error_text_layer), false); } else { send_to_phone(); } }
static void menu_select_click_callback(MenuLayer* menu_layer, MenuIndex* cell_index, void* callback_context) { realtime_transport_type_t *ttype = (realtime_transport_type_t *) callback_context; if (!layer_get_hidden(transport_type_to_loadinglayer_map[*ttype])) { APP_LOG(APP_LOG_LEVEL_DEBUG, "No clicks allowed while loading layer is visible"); return; } stop_t *stop; switch (cell_index->section) { case MENU_SECTION_MAIN: stop = get_stop(cell_index->row); if (stop == NULL) { return; } show_departures_window(stop->id, *ttype, true); break; } }
bool scroll_layer_get_shadow_hidden (const ScrollLayer* l) { SCROLL_GET; return layer_get_hidden(scroll->shadow_sublayer); }
void tick_handler(struct tm *tick_time, TimeUnits units_changed){ hour = tick_time->tm_hour; minute = tick_time->tm_min; day = tick_time->tm_wday; mday = tick_time->tm_mday; second = tick_time->tm_sec; if(hour > 12){ fixedHour = hour-13; } else if(hour != 0){ fixedHour = hour-1; } else if(hour == 0){ fixedHour = 11; } if(main_settings.progressiveDrunk == 1){ if(hour > 1 && hour < 14){ main_settings.wordPack = 1; } else if(hour > 13 && hour < 19){ main_settings.wordPack = 2; } else if(hour > 18 && hour < 2){ main_settings.wordPack = 3; } } snprintf(word1Buffer, sizeof(word1Buffer), "%s", hourWords[0][fixedHour]); text_layer_set_text(first_word_t, word1Buffer); bottomMin = (minute%10); if(minute < 10){ snprintf(word3Buffer, sizeof(word3Buffer), "%s", ones[0][(int)bottomMin]); teenStatus = 1; } else if(minute > 10 && minute < 20){ snprintf(word3Buffer, sizeof(word3Buffer), "%s", teens[0][(minute%10)]); if(minute < 17){ teenStatus = 1; } else{ teenStatus = 2; } } else{ snprintf(word3Buffer, sizeof(word3Buffer), "%s", tens[0][(minute/10)]); teenStatus = 0; } text_layer_set_text(third_word_t, word3Buffer); switch(teenStatus){ case 0: snprintf(word4Buffer, sizeof(word4Buffer), "%s", ones[0][(int)bottomMin]); text_layer_set_text(fourth_word_t, word4Buffer); if(layer_get_hidden(text_layer_get_layer(fourth_word_t))){ layer_set_hidden(text_layer_get_layer(fourth_word_t), false); } break; case 1: layer_set_hidden(text_layer_get_layer(fourth_word_t), true); break; case 2: text_layer_set_text(fourth_word_t, "teen"); break; } if(minute % 10 == 0){ if(layer_get_hidden(text_layer_get_layer(fourth_word_t)) == 0){ layer_set_hidden(text_layer_get_layer(fourth_word_t), true); } } else{ if(layer_get_hidden(text_layer_get_layer(fourth_word_t)) && teenStatus != 1){ layer_set_hidden(text_layer_get_layer(fourth_word_t), false); } } if(main_settings.slotUse == SLOT_USE_DATE){ if(tick_time->tm_sec != 0 && !change && units_changed != DAY_UNIT){ goto SKIP_DATE; } change = false; switch(main_settings.dateFormat){ case DATE_FORMAT_DDMMYY: strftime(slotBuffer, sizeof(slotBuffer), "%d/%m/%y", tick_time); break; case DATE_FORMAT_MMDDYY: strftime(slotBuffer, sizeof(slotBuffer), "%m/%d/%y", tick_time); break; case DATE_FORMAT_MONTHDAYYEAR: if(mday == 1 || mday == 21 || mday == 31){ strftime(slotBuffer, sizeof(slotBuffer), "%b %dst, %Y", tick_time); } else if(mday == 2 || mday == 22){ strftime(slotBuffer, sizeof(slotBuffer), "%b %dnd, %Y", tick_time); } else if(mday == 3 || mday == 23){ strftime(slotBuffer, sizeof(slotBuffer), "%b %drd, %Y", tick_time); } else{ strftime(slotBuffer, sizeof(slotBuffer), "%b %dth, %Y", tick_time); } break; case DATE_FORMAT_WEEKDAY: snprintf(slotBuffer, sizeof(slotBuffer), "%s, it's %s", phrases_get_slot_swear(), daysChar[0][day]); break; } text_layer_set_text(slot_t, slotBuffer); } else if(main_settings.slotUse == SLOT_USE_TEMPERATURE){ if(tick_time->tm_sec != 0 && !change && units_changed != DAY_UNIT){ goto SKIP_DATE; } change = false; snprintf(slotBuffer, sizeof(slotBuffer), "%s, %d degrees.", phrases_get_slot_swear(), main_settings.previousTemp); text_layer_set_text(slot_t, slotBuffer); } SKIP_DATE:; if(minute == 20){ if(hour == 4 || hour == 16){ text_layer_set_text(second_word_t, "blazeit"); } } if(charging){ if(animation_i){ animate_layer(battery_bar_layer, &GRect(0, 0, 144, 168), &GRect(144, 0, 144, 168), 1000, 0); } else{ animate_layer(battery_bar_layer, &GRect(-144, 0, 144, 168), &GRect(0, 0, 144, 168), 1000, 0); } animation_i = !animation_i; } else{ GRect frame = layer_get_frame(battery_bar_layer); if(frame.origin.x != 0){ animate_layer(battery_bar_layer, &GRect(-144, 0, 144, 168), &GRect(0, 0, 144, 168), 500, 0); } } if(second == 59 && main_settings.animation != ANIMATION_DISABLED){ switch(minute){ case 59: fire_animation(first_word_t, 100, layer_get_frame(text_layer_get_layer(first_word_t)), false); fire_animation(second_word_t, 200, layer_get_frame(text_layer_get_layer(second_word_t)), true); fire_animation(third_word_t, 300, layer_get_frame(text_layer_get_layer(third_word_t)), false); fire_animation(fourth_word_t, 400, layer_get_frame(text_layer_get_layer(fourth_word_t)), false); break; default: fire_animation(third_word_t, 100, layer_get_frame(text_layer_get_layer(third_word_t)), false); fire_animation(fourth_word_t, 200, layer_get_frame(text_layer_get_layer(fourth_word_t)), false); break; } } if(main_settings.seconds){ static char seconds_buffer[] = "59."; snprintf(seconds_buffer, sizeof(seconds_buffer), "%d", second); text_layer_set_text(seconds_t, seconds_buffer); } }
void handle_inverter() { if (layer_get_hidden(inverter_layer_get_layer(inverter_layer)) != (graphics_mode == GRAPHICS_MODE_NORMAL)) layer_set_hidden(inverter_layer_get_layer(inverter_layer), graphics_mode == GRAPHICS_MODE_NORMAL); }
static void inbox_received_handler(DictionaryIterator *iter, void *context) { if (!loaded) { layer_set_hidden(text_layer_get_layer(s_loading_text_layer), true); APP_LOG(APP_LOG_LEVEL_DEBUG, "Maybe its not this?"); loaded = true; APP_LOG(APP_LOG_LEVEL_DEBUG, "Maybe its this?"); } APP_LOG(APP_LOG_LEVEL_DEBUG, "Pebble received message from Phone!"); Tuple *action_string = dict_find(iter, KEY_ACTION); int length = 0; if (action_string) { length = strlen(action_string->value->cstring); if (listAction != NULL) { free(listAction); listAction = NULL; } listAction = (char*)malloc((length+1) * sizeof(char)); memcpy(listAction,action_string->value->cstring,(length+1) * sizeof(char)); APP_LOG(APP_LOG_LEVEL_DEBUG, "Received action of: \"%s\"", listAction); } if (strcmp(listAction, "response")==0){ APP_LOG(APP_LOG_LEVEL_DEBUG, "Received a http response from Phone!"); vibes_short_pulse(); Tuple *response_string = dict_find(iter, KEY_RESPONSE); Tuple *array_index = dict_find(iter,KEY_INDEX); int index_of_array = 0; if (array_index){ index_of_array = array_index->value->int32; } length = strlen(response_string->value->cstring); if (statusList[index_of_array] != NULL) { //free(statusList[index_of_array] ); statusList[index_of_array] = NULL; } statusList[index_of_array] = (char*)malloc((length+1) * sizeof(char)); memcpy(statusList[index_of_array],response_string->value->cstring,(length +1) * sizeof(char)); APP_LOG(APP_LOG_LEVEL_DEBUG, "HTTP Response: %s", statusList[index_of_array]); menu_layer_reload_data(s_menu_layer); } else { Tuple *array_size = dict_find(iter,KEY_SIZE); Tuple *array_string = dict_find(iter, KEY_LIST); int size_of_array = 0; if (array_size){ size_of_array = array_size->value->int32; } if (size_of_array > 0 && !layer_get_hidden(text_layer_get_layer(s_error_text_layer))) { layer_set_hidden(text_layer_get_layer(s_error_text_layer), true); } listSize = size_of_array; // Check it was found. If not, dict_find() returns NULL if(array_string) { // Get the length of the string length = strlen(array_string->value->cstring); // Free any previous data if(s_buffer != NULL) { free(s_buffer); s_buffer = NULL; } // Allocate exactly the right amount of memory. // This is usually the number of elements multiplied by // the size of each element, returned by sizeof() s_buffer = (char*)malloc((length+1) * sizeof(char)); // Copy in the string to the newly allocated buffer //strcpy(s_buffer, array_string->value->cstring); memcpy(s_buffer,array_string->value->cstring,(length+1) * sizeof(char)); APP_LOG(APP_LOG_LEVEL_DEBUG, "Size retrieved from phone: %d", size_of_array); APP_LOG(APP_LOG_LEVEL_DEBUG, "List retrieved from phone: %s", s_buffer); int bytesWritten = 0; int bytesSizeWritten = 0; if (size_of_array == 0) { bytesWritten = persist_write_string(PERSIST_LIST,""); bytesSizeWritten = persist_write_int(PERSIST_LIST_SIZE,0); APP_LOG(APP_LOG_LEVEL_DEBUG, "Writing Empty values to persistent store."); } else { bytesWritten = persist_write_string(PERSIST_LIST,s_buffer); bytesSizeWritten = persist_write_int(PERSIST_LIST_SIZE,size_of_array); APP_LOG(APP_LOG_LEVEL_DEBUG, "Written to persistent storage (size): %d", bytesSizeWritten); APP_LOG(APP_LOG_LEVEL_DEBUG, "Written to persistent storage (list): %d", bytesWritten); update_menu_data((int)size_of_array); } menu_layer_reload_data(s_menu_layer); if (layer_get_hidden(text_layer_get_layer(s_error_text_layer)) && listString == 0) { layer_set_hidden(text_layer_get_layer(s_error_text_layer), false); } if(s_buffer != NULL) { free(s_buffer); s_buffer = NULL; APP_LOG(APP_LOG_LEVEL_DEBUG, "Freed s_buffer memory"); } } } if (listAction != NULL){ free(listAction); listAction = NULL; } }
void process_eventsmenu_message(DictionaryIterator *received) { Tuple *tuple; tuple = dict_find(received, KEY_INIT); if (tuple) { if (tuple->value->int8 == 0) { eventsmenu_firstload(); } else { if (!persist_exists(PERSIST_KEY_VERSION)) { if(persist_exists(PERSIST_EVENT_TITLE)) persist_write_int(PERSIST_KEY_VERSION, 21); else persist_write_int(PERSIST_KEY_VERSION, APP_VERSION); } if (persist_read_int(PERSIST_KEY_VERSION) < 22) { ui_messagebox_show("What's new", "Version 2.2: Added event reminders. To enable, visit app settings on phone."); } if (persist_read_int(PERSIST_KEY_VERSION) < 25) { ui_messagebox_show("What's new", "Version 2.5: Added auto refresh. To enable, visit app settings on phone."); } if (persist_read_int(PERSIST_KEY_VERSION) < APP_VERSION) { persist_write_int(PERSIST_KEY_VERSION, APP_VERSION); } } send_client_secret(); wakeup_schedule_sync(); } tuple = dict_find(received, KEY_SHOW_LOADING); if(tuple) { eventsmenu_loading(); } tuple = dict_find(received, KEY_EVENT_ID); if(tuple) { current_event_id = tuple->value->uint8; if (persist_exists((current_event_id + 1) * PERSIST_EVENT_FIELDCOUNT + PERSIST_EVENT_TITLE)) persist_delete((current_event_id + 1) * PERSIST_EVENT_FIELDCOUNT + PERSIST_EVENT_TITLE); } tuple = dict_find(received, KEY_EVENT_TITLE); if(tuple) { persist_write_string(PERSIST_EVENT_TITLE + current_event_id*PERSIST_EVENT_FIELDCOUNT, (char *)tuple->value->data); } tuple = dict_find(received, KEY_EVENT_START_DATE); if(tuple) { persist_write_int(PERSIST_EVENT_START_DATE + current_event_id*PERSIST_EVENT_FIELDCOUNT, tuple->value->uint32); } tuple = dict_find(received, KEY_EVENT_END_DATE); if(tuple) { persist_write_int(PERSIST_EVENT_END_DATE + current_event_id*PERSIST_EVENT_FIELDCOUNT, tuple->value->uint32); } tuple = dict_find(received, KEY_EVENT_LOCATION); if(tuple) { persist_write_string(PERSIST_EVENT_LOCATION + current_event_id*PERSIST_EVENT_FIELDCOUNT, (char *)tuple->value->data); } tuple = dict_find(received, KEY_EVENT_ATTENDEES); if(tuple) { persist_write_string(PERSIST_EVENT_ATTENDEES + current_event_id*PERSIST_EVENT_FIELDCOUNT, (char *)tuple->value->data); } tuple = dict_find(received, KEY_EVENT_BODY); if(tuple) { persist_write_string(PERSIST_EVENT_BODY + current_event_id*PERSIST_EVENT_FIELDCOUNT, (char *)tuple->value->data); } tuple = dict_find(received, KEY_REFRESH_UI); if(tuple) { APP_LOG(APP_LOG_LEVEL_DEBUG, "Refreshing events menu"); menu_layer_reload_data(s_menu_layer); text_layer_set_text(s_title_layer, "Events (online)"); wakeup_schedule_event_reminder(); if (layer_get_hidden(menu_layer_get_layer(s_menu_layer))) { layer_set_hidden(text_layer_get_layer(s_message_layer), true); layer_set_hidden(menu_layer_get_layer(s_menu_layer), false); } } }
bool trend_arrow_component_hidden(TrendArrowComponent *c) { return layer_get_hidden(bitmap_layer_get_layer(c->icon_layer)); }