void main_menu_set_selected_index(uint16_t section, uint16_t row){ MenuIndex menu_index; menu_index.section = section; menu_index.row = row; menu_layer_reload_data(s_main_menu_layer); menu_layer_set_selected_index(s_main_menu_layer, menu_index, MenuRowAlignTop, false); }
void RegisterMenuCellList(Menu *menu, const char *sectionName, MenuCellDescription *list, uint16_t count) { DEBUG_LOG("RegisterMenuCellList"); if(count == 0) { ClearMenuCellList(menu); return; } menu->useCallbackFunctions = false; menu->menuCountCallback = NULL; menu->menuNameCallback = NULL; menu->menuDescriptionCallback = NULL; menu->menuSelectCallback = NULL; menu->menuSectionCountCallback = NULL; menu->menuSectionNameCallback = NULL; menu->cellList = list; menu->cellCount = count; menu->sectionName = sectionName; if(menu->menuLayerInitialized) { menu_layer_reload_data(menu->menuLayer); MenuIndex index = {.section = 0, .row = 0}; menu_layer_set_selected_index(menu->menuLayer, index, MenuRowAlignCenter, false); } if(menu->mainMenu) ShowMenuArrow(); }
void RegisterMenuCellCallbacks(Menu *menu, MenuSectionNameCallback menuSectionNameCallback, MenuSectionCountCallback menuSectionCountCallback, MenuCountCallback countCallback, MenuNameCallback nameCallback, MenuDescriptionCallback descriptionCallback, MenuSelectCallback selectCallback) { DEBUG_LOG("RegisterMenuCellCallbacks"); menu->useCallbackFunctions = true; menu->menuCountCallback = countCallback; menu->menuNameCallback = nameCallback; menu->menuDescriptionCallback = descriptionCallback; menu->menuSelectCallback = selectCallback; menu->menuSectionCountCallback = menuSectionCountCallback; menu->menuSectionNameCallback = menuSectionNameCallback; if(!menu->menuCountCallback) { ClearMenuCellList(menu); return; } menu->cellCount = 0; menu->cellList = NULL; menu->sectionName = NULL; if(menu->mainMenu) { uint16_t totalCells = GetMenuTotalCellCount(menu); if(totalCells > 0) { MenuIndex index = {.section = 0, .row = 0}; menu_layer_set_selected_index(menu->menuLayer, index, MenuRowAlignCenter, false); menu_layer_reload_data(menu->menuLayer); ShowMenuArrow(); } else
void InboxShow(const char const* uri) { if (uri) { strncpy(s_uri, uri, 256); } // at this point there may be no data to work with, if so, show 'please wait' screen. if (!md_loaded()) { PleaseWaitShow("Inbox loading"); s_waitingForData = true; return; } int pos = -1; if (uri) { pos = md_index(uri); } if (pos >= 0) { MenuIndex index; index.row = pos; index.section = 0; menu_layer_set_selected_index(&s_menu_layer, index, MenuRowAlignCenter, false); } window_stack_push(&s_window, true); }
MenuIndex get_current_session_from_time() { time_t now = time(NULL); struct tm *tm_now = localtime(&now); MenuIndex current = {.section = 0, .row = 0}; if (tm_now->tm_mon != event_month - 1 || tm_now->tm_mday != event_day) { return current; } for(int ts_idx=0; ts_idx<schedule.num_slots; ts_idx++) { TimeSlot *ts = &schedule.slots[ts_idx]; if (tm_now->tm_hour < ts->start_hour) { break; } else if(tm_now->tm_hour == ts->start_hour && tm_now->tm_min < ts->start_min) { break; } current.section = ts_idx; } return current; } MenuIndex get_current_session_from_args() { int args = launch_get_args(); MenuIndex current = {.section = args / 10, .row = args % 10}; return current; } MenuIndex get_current_session() { #ifdef PBL_COLOR if (launch_reason() == APP_LAUNCH_TIMELINE_ACTION && launch_get_args() > 0) { return get_current_session_from_args(); } #endif return get_current_session_from_time(); } static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_frame(window_layer); menu_schedule = menu_layer_create(bounds); #ifdef PBL_COLOR menu_layer_set_normal_colors(menu_schedule, ROW_BG_COLOR, ROW_FG_COLOR); menu_layer_set_highlight_colors(menu_schedule, HIGHLIGHT_BG_COLOR, HIGHLIGHT_FG_COLOR); #endif menu_layer_set_callbacks(menu_schedule, NULL, (MenuLayerCallbacks) { .get_num_sections = menu_get_num_sections_callback, .get_num_rows = menu_get_num_rows_callback, .get_header_height = menu_get_header_height_callback, .get_cell_height = menu_get_height_callback, .draw_header = menu_draw_header_callback, .draw_row = menu_draw_row_callback, .select_click = menu_select_callback, }); menu_layer_set_click_config_onto_window(menu_schedule, window); MenuIndex idx = get_current_session(); menu_layer_set_selected_index(menu_schedule, idx, MenuRowAlignCenter, false); layer_add_child(window_layer, menu_layer_get_layer(menu_schedule)); }
void arrivals_success(int32_t cookie, int http_status, DictionaryIterator* received, void* context) { Tuple *t = dict_find(received, 1); char *v = t->value->cstring; uint16_t index = 0; uint16_t len = t->length; arrivalsCount = 0; int16_t time = 0; MenuIndex top = { 0, 0 }; PblTm now; get_time(&now); if (clock_is_24h_style()) { string_format_time(arrival_time_str, sizeof(arrival_time_str), "Updated: %H:%M", &now); } else { string_format_time(arrival_time_str, sizeof(arrival_time_str), "Updated: %l:%M %p", &now); } for(unsigned char i=0;i<MAX_ARRIVALS && index < len;i++) { //stokenize(char *source, uint16_t index, char delimiter, char *target, uint16_t max_length) index = stokenize(v, index, ':', ARRIVALS[i].route, ARRIVAL_ROUTE_LENGTH, len); index = stokenize(v, index, ':', ARRIVALS[i].actual, sizeof(ARRIVALS[i].actual), len); index = stokenize(v, index, ':', ARRIVALS[i].scheduled, sizeof(ARRIVALS[i].scheduled), len); //TODO: DRY time = satoi(ARRIVALS[i].actual, strlen(ARRIVALS[i].actual)); if(abs(time) > 99*60 + 59) //Maximum displayable value. time = (99*60 + 59) * (time < 0 ? -1 : 1); if(time > 60 || time < -60) { snprintf(ARRIVALS[i].actual, ARRIVAL_TIME_LENGTH, "%d:%02d", time / 60, abs(time % 60)); } else { snprintf(ARRIVALS[i].actual, ARRIVAL_TIME_LENGTH, "%d", time % 60); } time = satoi(ARRIVALS[i].scheduled, strlen(ARRIVALS[i].scheduled)); if(abs(time) > 99*60 + 59) //Maximum displayable value. time = (99*60 + 59) * (time < 0 ? -1 : 1); if(time > 60 || time < -60) { snprintf(ARRIVALS[i].scheduled, ARRIVAL_TIME_LENGTH, "%d:%02d", time / 60, abs(time % 60)); } else { snprintf(ARRIVALS[i].scheduled, ARRIVAL_TIME_LENGTH, "%d", time % 60); } APP_LOG(APP_LOG_LEVEL_INFO, "Received route:%s actual:%s scheduled:%s (index:%d/%d)", ARRIVALS[i].route, ARRIVALS[i].actual, ARRIVALS[i].scheduled, index, len); ++arrivalsCount; } menu_layer_reload_data(&_arrivalsMenu); menu_layer_set_selected_index(&_arrivalsMenu, top, MenuRowAlignBottom, false); }
void ui_refreshItems(int selectPos) { if (selectPos != -1) { MenuIndex idx; idx.section = 0; idx.row = selectPos; menu_layer_set_selected_index(menu, idx, MenuRowAlignTop, false); } menu_layer_reload_data(menu); }
static void window_appear(Window *window) { // Session deletion from review UI could the selected row when returning to this window MenuIndex menu_index = menu_layer_get_selected_index(menu_layer_main_menu); uint16_t section = menu_index.section; uint16_t row = menu_index.row; uint16_t num_rows = num_rows_callback(menu_layer_main_menu, section, NULL); window_unload(window); window_load(window); if (row >= num_rows) { // Exception handling for review UI deleting a session menu_layer_set_selected_index(menu_layer_main_menu, MenuIndex(section,0), MenuRowAlignCenter, false); } else { menu_layer_set_selected_index(menu_layer_main_menu, MenuIndex(section,row), MenuRowAlignCenter, false); } layer_mark_dirty(menu_layer_get_layer(menu_layer_main_menu)); }
static void select_next_font_handler(ClickRecognizerRef recognizer, void *context) { current_font++; if ((unsigned)current_font >= NUM_FONTS) { current_font = 0; } MenuIndex idx = menu_layer_get_selected_index(menu_layer); idx.row = current_font; menu_layer_set_selected_index(menu_layer, idx, MenuRowAlignCenter, false); show_selected_font_and_message(); }
static void select_previous_font_handler(ClickRecognizerRef recognizer, void *context) { current_font--; if (current_font < 0) { current_font = NUM_FONTS - 1; } MenuIndex idx = menu_layer_get_selected_index(menu_layer); idx.row = current_font; menu_layer_set_selected_index(menu_layer, idx, MenuRowAlignCenter, false); show_selected_font_and_message(); }
void multi_code_window_second_tick(int seconds) { if (refresh_required) { menu_layer_reload_data(multi_code_menu_layer); menu_layer_set_selected_index(multi_code_menu_layer, MenuIndex(0, otp_selected), MenuRowAlignCenter, true); if(fonts_changed) multi_code_set_fonts(); if (colors_changed) multi_code_apply_display_colors(); refresh_required = false; } }
static void set_selected_speed() { MenuIndex menu_index; menu_index.section = 0; menu_index.row = 0; for(uint16_t i=0;i<LENGTH(speeds); i++) { if (speeds[i].interval == interval) { menu_index.row = i; break; } } menu_layer_set_selected_index(s_speed_menu_layer, menu_index, MenuRowAlignCenter, true); }
void handle_group_window_appear(struct Window *window){ if(currentWindow == WINDOW_HOME){ device_count = 0; devices_loaded = 0; menu_layer_set_selected_index(&groupLayer, MenuIndex(0, 0), MenuRowAlignTop, false); } currentWindow = WINDOW_ROOM; if(devices_loaded < device_count || devices_loaded == 0){ if(!request_in_progress){ request_device_list(); } } }
static void tick_second_handler( struct tm *time, const TimeUnits unit ) { /* Bail out here if the timezone isn't set. */ if ( have_tz_offset() == false ) return; /* Get the UTC time and update the timers with it. */ struct tm utc = *time; time_convert_local_to_utc(&utc); update_event_times(&utc); /* Reload the menu in case row counts change. */ menu_layer_reload_data(event_menu); /* Stuff to do on the first tick. */ if ( first_tick == true ) { /* If the time zone message exists, we can remove it now. */ if ( tz_message != NULL ) { text_layer_destroy(tz_message); tz_message = NULL; } /* Set the selection to the first menu item on startup. */ menu_layer_set_selected_index(event_menu, (MenuIndex) { 0, 0 }, MenuRowAlignBottom, false); /* The menu layer is created hidden so we don't see * all the timers set to 0:00 before the first tick. */ layer_set_hidden(menu_layer_get_layer(event_menu), false); first_tick = false; } layer_mark_dirty(menu_layer_get_layer(event_menu)); }
// Here we capture when a user selects a menu item void menu_select_callback(MenuLayer *menu_layer, MenuIndex *cell_index, void *data) { // Handle transitions to different trial types uint64_t time; switch (current_type) { case SETUP: if (cell_index->row == 0) { enable_tilt_scroll(); } current_type = PRACTICE_KNOWN; break; case PRACTICE_KNOWN: current_type = PRACTICE_UNKNOWN; break; case PRACTICE_UNKNOWN: current_type = TRIAL_KNOWN; trial_num = 0; break; case TRIAL_KNOWN: // Finish the trial time = stop_timer(&time_sec, &time_msec); time_results[trial_num] = time; accuracy_results[trial_num] = cell_index->row - known_trials[trial_num]; // Transition to next trial if (trial_num == NUM_TRIALS - 1) { current_type = TRIAL_UNKNOWN; trial_num = 0; } else { trial_num++; } break; case TRIAL_UNKNOWN: // Finish the trial time = stop_timer(&time_sec, &time_msec); time_results[trial_num + NUM_TRIALS] = time; accuracy_results[trial_num + NUM_TRIALS] = cell_index->row - unknown_trials[trial_num]; // Transition to next trial if (trial_num == NUM_TRIALS - 1) { current_type = RESULTS; trial_num = 0; // Log the results char str[256]; int cx = 0; int i; for (i = 0; i < NUM_TRIALS; i++) { cx += snprintf(str + cx, 256 - cx, "%llu,", time_results[i]); } APP_LOG(APP_LOG_LEVEL_DEBUG, str); cx = 0; memset(str, 0, 256); for (i = NUM_TRIALS; i < NUM_TRIALS * 2; i++) { cx += snprintf(str + cx, 256 - cx, "%llu,", time_results[i]); } APP_LOG(APP_LOG_LEVEL_DEBUG, str); cx = 0; memset(str, 0, 256); for (i = 0; i < NUM_TRIALS; i++) { cx += snprintf(str + cx, 512 - cx, "%d,", accuracy_results[i]); } APP_LOG(APP_LOG_LEVEL_DEBUG, str); cx = 0; memset(str, 0, 256); for (i = NUM_TRIALS; i < NUM_TRIALS * 2; i++) { cx += snprintf(str + cx, 512 - cx, "%d,", accuracy_results[i]); } APP_LOG(APP_LOG_LEVEL_DEBUG, str); } else { trial_num++; } break; case RESULTS: return; } // Start tilt select timer start_timer(&select_timeout_sec, &select_timeout_msec); // If we're starting a new timed trial, start the timer if (current_type == TRIAL_KNOWN || current_type == TRIAL_UNKNOWN) { start_timer(&time_sec, &time_msec); } MenuIndex idx; idx.section = 0; idx.row = 0; menu_layer_set_selected_index(menu_layer, idx, MenuRowAlignCenter, false); menu_layer_reload_data(menu_layer); }