// Ticktimer Handler Update // s_nearbyStopsWindow: get current bus stop selection and scrolling offset. Request new data. // s_busArrivalsWindow: get current bus service selection and scrolling offset. Reqeust new data. static void tickHandler(struct tm *tickTime, TimeUnits unitsChanged) { if (window_stack_get_top_window() == s_nearbyStopsWindow) { requestData("location"); } else if (window_stack_get_top_window() == s_busArrivalsWindow) { requestData(lastStopRequest); } }
// Battery State Handler Update static void batteryHandler(BatteryChargeState charge) { if (window_stack_get_top_window() == s_nearbyStopsWindow) { layer_mark_dirty(s_battery); } else if (window_stack_get_top_window() == s_busArrivalsWindow) { layer_mark_dirty(s_battery2); } else if (window_stack_get_top_window() == s_splashWindow) { layer_mark_dirty(s_battery3); } else if (window_stack_get_top_window() == s_routeWindow) { layer_mark_dirty(s_battery4); } }
// Accelerometer Handler Update // s_nearbyStopsWindow: get current bus stop selection and scrolling offset. Request new data. // s_busArrivalsWindow: get current bus service selection and scrolling offset. Reqeust new data. static void accelerometerHandler(AccelAxisType axis, int32_t direction) { light_enable_interaction(); time_t now = time(NULL); if (difftime(now, lastUpdate) < MINIMUM_UPDATE_SECONDS) { return; } if (window_stack_get_top_window() == s_nearbyStopsWindow) { requestData("location"); } else if (window_stack_get_top_window() == s_busArrivalsWindow) { requestData(lastStopRequest); } }
void action_bar_layer_remove_from_window(ActionBarLayer *action_bar) { if (action_bar->window!=0) { Layer* cursor=&action_bar->window->layer; while (cursor->next_sibling!=0) { if (cursor->next_sibling==((Layer*)action_bar)) { cursor->next_sibling=action_bar->layer.next_sibling; break; } cursor=cursor->next_sibling; } action_bar->window->click_config_provider=0; action_bar->window->click_config_context=0; if (window_stack_get_top_window()==action_bar->window) { ClickConfig** clickConfig=getClickConfig (); int i; for (i=BUTTON_ID_UP;i<=BUTTON_ID_DOWN;i++) { if (clickConfig[i]->raw.up_handler==action_bar_click_handler_up) clickConfig[i]->raw.up_handler=0; if (clickConfig[i]->raw.down_handler==action_bar_click_handler_down) clickConfig[i]->raw.down_handler=0; } } action_bar->window=0; } }
void simply_window_stack_pop(SimplyWindowStack *self, SimplyWindow *window) { self->is_hiding = true; if (window->window == window_stack_get_top_window()) { bool animated = true; window_stack_pop(animated); } self->is_hiding = false; }
// Handles timer event when app has been idle for X minutes and auto-closes app static void autoclose_handler(void *data) { if (s_autoclose_timer != NULL) { s_autoclose_timer = NULL; if (s_autoclose_timeout != 0 && window_stack_get_top_window() == s_window) { // If autoclose is still enabled and the main window is on top, then exit the app window_stack_pop_all(false); } } }
static SimplyWindow *get_top_simply_window(Simply *simply) { Window *base_window = window_stack_get_top_window(); if (!base_window) { return NULL; } SimplyWindow *window = window_get_user_data(base_window); if (!window || (void*) window == simply->splash) { return NULL; } return window; }
void action_bar_layer_set_icon(ActionBarLayer *action_bar, ButtonId button_id, const GBitmap *icon) { bool hasSet=true; switch (button_id) { case(BUTTON_ID_UP):{action_bar->icons[0]=icon;}break; case(BUTTON_ID_SELECT):{action_bar->icons[1]=icon;}break; case(BUTTON_ID_DOWN):{action_bar->icons[2]=icon;}break; default:{hasSet=false;}break; } if (hasSet&&action_bar->click_config_provider!=0&&action_bar->window!=0&&window_stack_get_top_window()==action_bar->window) action_bar->click_config_provider (getClickConfig (),action_bar->context); }
static void msg_received(DictionaryIterator *iterator, void *context) { bool added; on_message(iterator, &added); if (!added) return; // Success. Rewind to the top of the stack and reload. while (window_stack_get_top_window() != context) window_stack_pop(true); menu_reload(context); }
static void update_event_image() { time_t temp = time(NULL); struct tm *tick_time = localtime(&temp); int desired_event_image = determine_event_image( tick_time->tm_hour, tick_time->tm_min); // APP_LOG(APP_LOG_LEVEL_DEBUG, "update_event_image: s_current_event_image=%i, desired_event_image=%i", s_current_event_image, desired_event_image); if (s_current_event_image != desired_event_image) { APP_LOG(APP_LOG_LEVEL_INFO, "update_event_image: changing image from %i to %i", s_current_event_image, desired_event_image); s_current_event_image = desired_event_image; vibes_double_pulse(); Window *window = window_stack_get_top_window(); // !! TODO: check if this is right Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); set_image(window_layer, bounds, s_current_event_image); } }
static void message_received(DictionaryIterator *iter, void *context) { Tuple *city = dict_find(iter, MESSAGE_KEY_CITY_CHANGE); bool dirty = false; if(city) { freeSchemePack(pack); uint32_t c = city->value->uint32; DLOG("city change: %d", c); settings.city = RESOURCE_ID_SCHEME_MSK + c; dirty = true; } Tuple *loc = dict_find(iter, MESSAGE_KEY_LOCALE_CHANGE); if(loc) { free_locale(); uint32_t l = loc->value->uint32; DLOG("locale change: %d", l); switch(settings.city) { case RESOURCE_ID_SCHEME_MSK: settings.scheme_locale = RESOURCE_ID_SCHEME_LOCALE_MSK_EN + l; break; case RESOURCE_ID_SCHEME_SPB: settings.scheme_locale = RESOURCE_ID_SCHEME_LOCALE_SPB_EN + l; break; case RESOURCE_ID_SCHEME_KIEV: settings.scheme_locale = RESOURCE_ID_SCHEME_LOCALE_KIEV_EN + l; break; case RESOURCE_ID_SCHEME_KHARKIV: settings.scheme_locale = RESOURCE_ID_SCHEME_LOCALE_KHARKIV_EN + l; break; case RESOURCE_ID_SCHEME_MINSK: settings.scheme_locale = RESOURCE_ID_SCHEME_LOCALE_MINSK_EN + l; break; } settings.locale = RESOURCE_ID_LOCALE_EN + l; dirty = true; } if(dirty) { loadSchemePack(settings.city, settings.scheme_locale); load_locale(settings.locale); save_settings(); Window *top = window_stack_get_top_window(); Layer *root = window_get_root_layer(top); layer_mark_dirty(root); open_update_window(); } }
bool pin_window_get_topmost_window(PinWindow *pin_window) { return window_stack_get_top_window() == pin_window->window; }
static void pop_window(bool animated) { window_stack_pop(animated); set_current_window(window_get_user_data(window_stack_get_top_window())); }
static void inbox_received_handler(DictionaryIterator *iter, void *context) { Tuple *result = dict_find(iter, RESULT); Tuple *showType = dict_find(iter, SHOW_TYPE); if(result) { APP_LOG(APP_LOG_LEVEL_INFO, "Phone sent: %d", (int)result->value->int32); if((int)result->value->int32 == RESULT_DONE) { isDone = true; APP_LOG(APP_LOG_LEVEL_INFO, "Phone sent done"); if(indexCur < NUM_ITEMS) { APP_LOG(APP_LOG_LEVEL_INFO, "All messages sent!"); send(SEND_DONE, 0); if (showType) { int type = (int)showType->value->int32; if (type == SHOW_ING) { APP_LOG(APP_LOG_LEVEL_INFO, "message: %s", ingredients); wdwScrollSetText(window_stack_get_top_window(), ingredients); } if (type == SHOW_STEP) { //char *message[NUM_ITEMS * MAX_LENGTH]; for(int i = 0; i < NUM_ITEMS; i++) { if (dataItems[i][0] != '\0') { wdwScrollSetText(window_stack_get_top_window(), dataItems[i]); APP_LOG(APP_LOG_LEVEL_INFO, "dataitem[%d]: %s", i, dataItems[i]); } } } } } indexCur = 0; } else if((int)result->value->int32 == RESULT_SENDING) { isDone = false; int index = 0; Tuple *item = dict_find(iter, INDEX); Tuple *ingredient = dict_find(iter, TYPE_INGREDIENT); Tuple *step = dict_find(iter, TYPE_STEP); if(item) { index = (int)item->value->int32; APP_LOG(APP_LOG_LEVEL_INFO, "Found item %d", index); } if (item || ingredient || step) { Tuple *title = dict_find(iter, TYPE_TITLE); static char buffer[NUM_ITEMS*MAX_LENGTH]; if (title && item) { snprintf(buffer, sizeof(buffer), "#%d: %s", index, title->value->cstring); strcpy(dataItems[index], buffer); APP_LOG(APP_LOG_LEVEL_INFO, "%s", buffer); } if (ingredient) { //snprintf(buffer, sizeof(buffer), "#%d: %s", index, ingredient->value->cstring); //strcpy(dataItems[index], buffer); memset(&ingredients[0], 0, sizeof(ingredients)); snprintf(buffer, sizeof(buffer), "%s", ingredient->value->cstring); strcpy(ingredients, buffer); APP_LOG(APP_LOG_LEVEL_INFO, "%s", buffer); } if (step) { //memset(&ingredients[0], 0, sizeof(ingredients)); memset(&dataItems[0], 0, sizeof(dataItems)); snprintf(buffer, sizeof(buffer), "%s", step->value->cstring); char copyBuffer[NUM_ITEMS*MAX_LENGTH]; strcpy(copyBuffer, buffer); dataItemsIndex = -1; char *split = strtokC(copyBuffer, DELIMITER); APP_LOG(APP_LOG_LEVEL_INFO, "split %s", split); while (split != NULL && dataItemsIndex < NUM_ITEMS) { dataItemsIndex++; strcpy(dataItems[dataItemsIndex], split); APP_LOG(APP_LOG_LEVEL_INFO, "copied %s", dataItems[dataItemsIndex]); split = strtokC (NULL, DELIMITER); } APP_LOG(APP_LOG_LEVEL_INFO, "%s", buffer); } indexCur = index + 1; APP_LOG(APP_LOG_LEVEL_INFO, "set indexCurr to %d", index); if (indexCur < NUM_ITEMS && !isDone) { send(SEND_NEXT, indexCur); APP_LOG(APP_LOG_LEVEL_INFO, "Send next message: %d", indexCur); } } } } }
/* Handles the user pressing the back button (returns the user to the main menu) */ void back_handler(ClickRecognizerRef recognizer, void* context) { app_timer_cancel(timer); // Stop polling for the current temperature window_stack_pop(true); window = window_stack_get_top_window(); }
void action_bar_layer_set_click_config_provider(ActionBarLayer *action_bar, ClickConfigProvider click_config_provider) { action_bar->click_config_provider=click_config_provider; if (click_config_provider!=0&&action_bar->window!=0&&window_stack_get_top_window()==action_bar->window) click_config_provider (getClickConfig (),action_bar->context); }
bool details_is_on_top() { return details_window == window_stack_get_top_window(); }
void layer_mark_dirty(Layer *layer) { if (layer!=0&&window_stack_get_top_window()==layer->window) markDirty (true); }
void dashboard_init(void) { dashboard_window = window_create(); #ifdef PBL_SDK_2 window_set_fullscreen(dashboard_window,true); #endif window_set_background_color(dashboard_window,GColorBlack); window_set_click_config_provider(dashboard_window, dashboard_click_config_provider); window_stack_push(dashboard_window, true); dashboard_window_layer = window_get_root_layer(dashboard_window); GRect c1_bounds = layer_get_bounds(dashboard_window_layer); c1_text_layer = text_layer_create(c1_bounds); text_layer_set_background_color(c1_text_layer,GColorBlack); text_layer_set_text_color(c1_text_layer,GColorWhite); text_layer_set_font(c1_text_layer,fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD)); text_layer_set_text(c1_text_layer, "Starting up..."); text_layer_set_text_alignment(c1_text_layer,GTextAlignmentCenter); layer_add_child(dashboard_window_layer, text_layer_get_layer(c1_text_layer)); GSize v1_size = {.w=c1_bounds.size.w,.h=c1_bounds.size.h-42}; GPoint v1_point = {.x=0,.y=8}; GRect v1_bounds = {.size=v1_size,.origin=v1_point}; v1_text_layer = text_layer_create(v1_bounds); text_layer_set_background_color(v1_text_layer,GColorClear); text_layer_set_text_color(v1_text_layer,GColorWhite); text_layer_set_font(v1_text_layer,fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD)); text_layer_set_text(v1_text_layer, ""); text_layer_set_text_alignment(v1_text_layer,GTextAlignmentCenter); layer_add_child(dashboard_window_layer, text_layer_get_layer(v1_text_layer)); GSize c2_size = {.w=v1_bounds.size.w,.h=v1_bounds.size.h-8}; GPoint c2_point = {.x=0,.y=50}; GRect c2_bounds = {.size=c2_size,.origin=c2_point}; c2_text_layer = text_layer_create(c2_bounds); text_layer_set_background_color(c2_text_layer,GColorClear); text_layer_set_text_color(c2_text_layer,GColorWhite); text_layer_set_font(c2_text_layer,fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD)); text_layer_set_text(c2_text_layer, ""); text_layer_set_text_alignment(c2_text_layer,GTextAlignmentCenter); layer_add_child(dashboard_window_layer, text_layer_get_layer(c2_text_layer)); GSize v2_size = {.w=c2_bounds.size.w,.h=c2_bounds.size.h-42}; GPoint v2_point = {.x=0,.y=58}; GRect v2_bounds = {.size=v2_size,.origin=v2_point}; v2_text_layer = text_layer_create(v2_bounds); text_layer_set_background_color(v2_text_layer,GColorClear); text_layer_set_text_color(v2_text_layer,GColorWhite); text_layer_set_font(v2_text_layer,fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD)); text_layer_set_text(v2_text_layer, ""); text_layer_set_text_alignment(v2_text_layer,GTextAlignmentCenter); layer_add_child(dashboard_window_layer, text_layer_get_layer(v2_text_layer)); GSize c3_size = {.w=v2_bounds.size.w,.h=v2_bounds.size.h-8}; GPoint c3_point = {.x=0,.y=100}; GRect c3_bounds = {.size=c3_size,.origin=c3_point}; c3_text_layer = text_layer_create(c3_bounds); text_layer_set_background_color(c3_text_layer,GColorClear); text_layer_set_text_color(c3_text_layer,GColorWhite); text_layer_set_font(c3_text_layer,fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD)); text_layer_set_text(c3_text_layer, ""); text_layer_set_text_alignment(c3_text_layer,GTextAlignmentCenter); layer_add_child(dashboard_window_layer, text_layer_get_layer(c3_text_layer)); GSize v3_size = {.w=c3_bounds.size.w,.h=c3_bounds.size.h}; GPoint v3_point = {.x=0,.y=108}; GRect v3_bounds = {.size=v3_size,.origin=v3_point}; v3_text_layer = text_layer_create(v3_bounds); text_layer_set_background_color(v3_text_layer,GColorClear); text_layer_set_text_color(v3_text_layer,GColorWhite); text_layer_set_font(v3_text_layer,fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD)); text_layer_set_text(v3_text_layer, ""); text_layer_set_text_alignment(v3_text_layer,GTextAlignmentCenter); layer_add_child(dashboard_window_layer, text_layer_get_layer(v3_text_layer)); GSize m_size = {.w=v3_bounds.size.w,.h=v3_bounds.size.h-8}; GPoint m_point = {.x=0,.y=152}; GRect m_bounds = {.size=m_size,.origin=m_point}; m_text_layer = text_layer_create(m_bounds); text_layer_set_font(m_text_layer,fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD)); text_layer_set_text(m_text_layer, ""); text_layer_set_text_alignment(m_text_layer,GTextAlignmentCenter); layer_add_child(dashboard_window_layer, text_layer_get_layer(m_text_layer)); clear_timer = app_timer_register(5000,dashboard_clear,dashboard_window); } void dashboard_deinit(void) { app_timer_cancel(clear_timer); window_destroy(dashboard_window); } void return_to_dashboard(bool animated){ while(window_stack_get_top_window()!=dashboard_window){ window_stack_pop(animated); } }