BatteryComponent* battery_component_create(Layer *parent, int16_t x, int16_t y, bool align_right) { battery_state_service_subscribe(battery_handler); BatteryComponent *c = malloc(sizeof(BatteryComponent)); c->icon_layer = NULL; c->icon_bitmap = NULL; c->text_layer = NULL; if (get_prefs()->battery_as_number) { FontChoice font = get_font(BATTERY_FONT); c->text_layer = add_text_layer( parent, GRect(x, y - font.padding_top + font.padding_bottom, BATTERY_TEXT_WIDTH, font.height + font.padding_top + font.padding_bottom), fonts_get_system_font(font.key), element_fg(parent), align_right ? GTextAlignmentRight : GTextAlignmentLeft ); } else { c->icon_layer = bitmap_layer_create(GRect(x, y + BATTERY_ICON_TOP_FUDGE, BATTERY_ICON_WIDTH, BATTERY_ICON_HEIGHT)); bitmap_layer_set_compositing_mode(c->icon_layer, element_comp_op(parent)); layer_add_child(parent, bitmap_layer_get_layer(c->icon_layer)); } // XXX s_component = c; battery_handler(battery_state_service_peek()); return c; }
static void update_time() { time_t temp = time(NULL); struct tm *tick_time = localtime(&temp); min = tick_time->tm_min; if(min == 59 && hour_vibrate == 1){ vibes_short_pulse(); } if (clock_is_24h_style() == twenty_four_hour_format){ strftime(buffer, sizeof(buffer), "%H:%M", tick_time); }else { strftime(buffer, sizeof(buffer), "%I:%M", tick_time); } if(change_date_format == 1){ strftime(date, sizeof(date),"%d/%m/%y", tick_time); } else{ strftime(date, sizeof(date),"%D", tick_time); } strftime(weekday, sizeof(weekday),"%A", tick_time); for(char* pc=weekday;*pc!=0;++pc) *pc = lower_to_upper(*pc); text_layer_set_text(lower_text_layer, date); text_layer_set_text(upper_text_layer, buffer); battery_handler(battery_state_service_peek()); }
static void window_load(Window *window) { window_set_background_color(window, GColorBlack); canvas = layer_create(GRect(0, 0, SCREEN_WIDTH , SCREEN_HEIGHT)); layer_set_update_proc(canvas, (LayerUpdateProc) render); layer_add_child(window_get_root_layer(window), canvas); mTimeFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_TREBUCHET_40)); mTimeFontBold = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_TREBUCHET_BOLD_40)); mSmallFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_TREBUCHET_BOLD_24)); mTinyFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_TREBUCHET_16)); // Init all text fields const int mTwoDigitTextSize = sizeof("00:00 "); mDayText = malloc(mTwoDigitTextSize); mMonthText = malloc(mTwoDigitTextSize); mYearText = malloc(mTwoDigitTextSize); mHourText = malloc(mTwoDigitTextSize); mMinuteText = malloc(mTwoDigitTextSize); mSecondText = malloc(mTwoDigitTextSize); // Set initial time so display isn't blank struct tm* t; time_t temp; temp = time(NULL); t = localtime(&temp); set_time_display(t); battery_handler(battery_state_service_peek()); }
static void window_load(Window *window) { mBackgroundColor = GColorBlack; mTextColor = GColorWhite; #if PBL_COLOR lightColor = GColorMintGreen; darkColor = GColorDarkGreen; window_set_background_color(window, darkColor); #else window_set_background_color(window, mBackgroundColor); #endif // PBL_COLOR bgLayer = layer_create(GRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)); layer_set_update_proc(bgLayer, (LayerUpdateProc)render_bg); layer_add_child(window_get_root_layer(window), bgLayer); timeLayer = layer_create(GRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)); layer_set_update_proc(timeLayer, (LayerUpdateProc)render_time); layer_add_child(window_get_root_layer(window), timeLayer); mTimeFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BITWISE_16)); mTimeText = malloc(5); // HH:MM mDateText = malloc(5); // MM-DD struct tm* t; time_t temp; temp = time(NULL); t = localtime(&temp); set_time_display(t); bt_handler(bluetooth_connection_service_peek()); battery_handler(battery_state_service_peek()); }
static void update_all(void) { update_minute(); update_daily(); update_weather(FORCE_WEATHER_UPDATE); battery_handler(battery_state_service_peek()); // force refresh bluetooth_handler(bluetooth_connection_service_peek()); }
// WINDOW CREATION // static void main_window_load(Window *window) { // Create time TextLayer s_time_layer = text_layer_create(GRect(0, -3, 144, 171)); // Note the negative Y-axis value for better positioning. text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, GColorBlack); text_layer_set_text(s_time_layer, "TIME: 00:00"); text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_time_layer, GTextAlignmentLeft); // Create Bluetooth TextLayer s_bluetooth_layer = text_layer_create(GRect(0, 95, 144, 14)); // A single text line is 14px high text_layer_set_background_color(s_bluetooth_layer, GColorClear); text_layer_set_text_color(s_bluetooth_layer, GColorBlack); text_layer_set_text(s_bluetooth_layer, "CONNECTED (Y/N): N"); text_layer_set_font(s_bluetooth_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_bluetooth_layer, GTextAlignmentLeft); // Create Battery TextLayer s_battery_layer = text_layer_create(GRect(0, 109, 144, 14)); text_layer_set_background_color(s_battery_layer, GColorClear); text_layer_set_text_color(s_battery_layer, GColorBlack); text_layer_set_text(s_battery_layer, "BATTERY LEVEL: N/A"); text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_battery_layer, GTextAlignmentLeft); // Create Battery TextLayer s_weather_layer = text_layer_create(GRect(0, 123, 144, 28)); text_layer_set_background_color(s_weather_layer, GColorClear); text_layer_set_text_color(s_weather_layer, GColorBlack); text_layer_set_text(s_weather_layer, "TEMPERATURE: Loading...\nWEATHER: Loading..."); text_layer_set_font(s_weather_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_weather_layer, GTextAlignmentLeft); // Create uptime TextLayer s_uptime_layer = text_layer_create(GRect(0, 151, 144, 14)); text_layer_set_background_color(s_uptime_layer, GColorClear); text_layer_set_text_color(s_uptime_layer, GColorBlack); text_layer_set_text(s_uptime_layer, "LOG UPTIME: 0h 0m 0s"); text_layer_set_font(s_uptime_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_uptime_layer, GTextAlignmentLeft); // Make sure the time is displayed from the start update_time(); // Show current connection state bt_handler(bluetooth_connection_service_peek()); // Get the current battery level battery_handler(battery_state_service_peek()); // Add child layers to the Window's root layer layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_uptime_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_bluetooth_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_battery_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer)); }
static void main_window_load(Window *window) { // Create root layer Layer *window_layer = window_get_root_layer(window); GRect window_bounds = layer_get_bounds(window_layer); // Create time TextLayer s_time_layer = text_layer_create(GRect(0, 35, window_bounds.size.w, 44)); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, GColorWhite); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); // Create date TextLayer s_date_layer = text_layer_create(GRect(0, 82, window_bounds.size.w, 26)); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_text_color(s_date_layer, GColorWhite); text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter); text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); // Create battery TextLayer s_battery_layer = text_layer_create(GRect(window_bounds.size.w / 2, 0, (window_bounds.size.w / 2) - 2, 18)); text_layer_set_background_color(s_battery_layer, GColorClear); text_layer_set_text_color(s_battery_layer, GColorWhite); text_layer_set_text_alignment(s_battery_layer, GTextAlignmentRight); text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); // Create Pi time BitmapLayer s_pi_bitmap = gbitmap_create_with_resource(RESOURCE_ID_PI_BACKGROUND); s_pi_layer = bitmap_layer_create(GRect(0,17,144,150)); bitmap_layer_set_bitmap(s_pi_layer, s_pi_bitmap); layer_set_hidden(bitmap_layer_get_layer(s_pi_layer), true); // Create bluetooth BitmapLayer s_bt_connected_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BT_CONNECTED); s_bt_disconnected_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BT_DISCONNECTED); s_bt_layer = bitmap_layer_create(GRect(3,3,12,11)); // Create bluetooth connected InverterLayer s_inv_layer = inverter_layer_create(GRect(0,0,window_bounds.size.w,window_bounds.size.h)); // Initialize watch state s_show_seconds_bool = true; battery_handler(battery_state_service_peek()); bluetooth_handler(bluetooth_connection_service_peek()); format_time(); // Add all layers to the Window's root layer layer_add_child(window_layer, text_layer_get_layer(s_time_layer)); layer_add_child(window_layer, text_layer_get_layer(s_battery_layer)); layer_add_child(window_layer, text_layer_get_layer(s_date_layer)); layer_add_child(window_layer, bitmap_layer_get_layer(s_bt_layer)); layer_add_child(window_layer, bitmap_layer_get_layer(s_pi_layer)); layer_add_child(window_layer, inverter_layer_get_layer(s_inv_layer)); }
static void second_handler(struct tm *tick_time, TimeUnits units_changed) { if (strcmp(text_layer_get_text(s_hacking_layer),"_hacking is our weapon")==0){ text_layer_set_text(s_hacking_layer, "hacking is our weapon"); }else{ text_layer_set_text(s_hacking_layer, "_hacking is our weapon"); } update_time(); battery_handler(battery_state_service_peek()); }
static void init_layers() { time_t temp = time(NULL); struct tm *tick_time = localtime(&temp); // Set current date update_date(tick_time, MINUTE_UNIT); // Set current time tick_handler(tick_time, MINUTE_UNIT); battery_handler(battery_state_service_peek()); }
static void main_window_load(Window *window) { s_main_layer = layer_create(GRect(0, 0, screen_width, screen_height)); layer_set_update_proc(s_main_layer, main_layer_update_proc); layer_add_child(window_get_root_layer(window), s_main_layer); update_time(); if (show_battery) { battery_handler(battery_state_service_peek()); } }
void window_load(Window *window) { s_text_layer = text_layer_create(GRect(0, 83, 132, 168)); text_layer_set_background_color(s_text_layer, GColorClear); text_layer_set_text(s_text_layer, GColorBlack); text_layer_set_text_alignment(s_text_layer, GTextAlignmentCenter); text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD)); layer_add_child(window_get_root_layer(s_window), text_layer_get_layer(s_text_layer)); // Create battery layer s_battery_layer = text_layer_create(GRect(0, 0, 144, 20)); text_layer_set_text_alignment(s_battery_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(s_window), text_layer_get_layer(s_battery_layer)); // Add inverter layer s_inv_layer = inverter_layer_create(GRect(0, 80, 144, 62)); layer_add_child(window_get_root_layer(s_window), inverter_layer_get_layer(s_inv_layer)); // Mult kirb layers s_kirbwalk0_bitmap = gbitmap_create_with_resource(RESOURCE_ID_KIRB_WALK_0); s_kirbwalk0_layer = bitmap_layer_create(GRect(-16, 60, 16, 16)); bitmap_layer_set_bitmap(s_kirbwalk0_layer, s_kirbwalk0_bitmap); s_kirbwalk1_bitmap = gbitmap_create_with_resource(RESOURCE_ID_KIRB_WALK_1); s_kirbwalk1_layer = bitmap_layer_create(GRect(63, 60, 16, 16)); bitmap_layer_set_bitmap(s_kirbwalk1_layer, s_kirbwalk1_bitmap); s_kirbwalk2_bitmap = gbitmap_create_with_resource(RESOURCE_ID_KIRB_WALK_2); s_kirbwalk2_layer = bitmap_layer_create(GRect(-16, 60, 16, 16)); bitmap_layer_set_bitmap(s_kirbwalk2_layer, s_kirbwalk2_bitmap); active_kirb = &s_kirbwalk1_layer; active_frame = 1; dx = 1; layer_add_child(window_get_root_layer(s_window), bitmap_layer_get_layer(s_kirbwalk0_layer)); layer_add_child(window_get_root_layer(s_window), bitmap_layer_get_layer(s_kirbwalk1_layer)); layer_add_child(window_get_root_layer(s_window), bitmap_layer_get_layer(s_kirbwalk2_layer)); struct tm *t; time_t temp; temp = time(NULL); t = localtime(&temp); // Manually call the tick handler when window is done loading tick_handler(t, MINUTE_UNIT); // Manually call battery handler battery_handler(battery_state_service_peek()); // Start kirb moving timer = app_timer_register(delta, (AppTimerCallback) timer_callback, NULL); }
void initializeYBattery() { // Create day TextLayer s_battery_layer = text_layer_create(GRect(84, 88, 80, 30)); text_layer_set_background_color(s_battery_layer, GColorWhite); text_layer_set_text_color(s_battery_layer, GColorBlack); // Improve the day TextLayer layout text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text_alignment(s_battery_layer, GTextAlignmentLeft); // Get the current battery level battery_handler(battery_state_service_peek()); // Subscribe to the Battery State Service battery_state_service_subscribe(battery_handler); }
void init(void) { show_window(); // Begin Clock Ticking multi_window_tick_timer_service_subscribe(MINUTE_UNIT, tick_handler); //begin bluetooth service multi_window_bluetooth_connection_service_subscribe(bluetooth_handler); //initializing bluetooth state bluetooth_handler(bluetooth_connection_service_peek()); //begin battery service multi_window_battery_state_service_subscribe(battery_handler); //initializing battery battery_handler(battery_state_service_peek()); multi_window_accel_tap_service_subscribe(shake_handler); }
static void main_window_load(Window *window){ Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); GRect weather_bounds = GRect(0,PBL_IF_ROUND_ELSE(115,105), bounds.size.w, 50); s_status_bar = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(18,5), bounds.size.w, 50)); s_time_layer = text_layer_create(GRect(0, PBL_IF_ROUND_ELSE(43,35), bounds.size.w, 50)); //Load custom minimal font s_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_ROBOTO_REGULAR_DOS_48)); s_font_small = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_ROBOTO_REGULAR_DOS_12)); s_weather_bitmap = gbitmap_create_with_resource(getImageId(temperature)); s_weather_icon = bitmap_layer_create(weather_bounds); window_set_background_color(s_main_window, GColorVividCerulean); //Set time text layer attributes text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, GColorWhite); text_layer_set_text(s_time_layer, "00:00"); text_layer_set_font(s_time_layer, s_font); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); //Set status bar layer attributes text_layer_set_background_color(s_status_bar, GColorClear); text_layer_set_text_color(s_status_bar, GColorWhite); //text_layer_set_text(s_status_bar, "Battery status"); text_layer_set_font(s_status_bar, s_font_small); text_layer_set_text_alignment(s_status_bar, GTextAlignmentCenter); bitmap_layer_set_alignment(s_weather_icon, GAlignCenter); bitmap_layer_set_background_color(s_weather_icon, GColorClear); bitmap_layer_set_compositing_mode(s_weather_icon, GCompOpSet); layer_add_child(window_layer, text_layer_get_layer(s_time_layer)); layer_add_child(window_layer, text_layer_get_layer(s_status_bar)); bitmap_layer_set_bitmap(s_weather_icon, s_weather_bitmap); layer_add_child(window_layer, bitmap_layer_get_layer(s_weather_icon)); battery_handler(battery_state_service_peek()); }
void window_load_main(Window *window){ Layer *window_layer = window_get_root_layer(window); main_settings = get_settings(); theme = inverter_layer_create(GRect(0, 0, 144, 168)); first_word_t = text_layer_init(GRect(0, 0, 144, 168), GTextAlignmentLeft, 1); second_word_t = text_layer_init(GRect(0, 30, 144, 168), GTextAlignmentLeft, 2); third_word_t = text_layer_init(GRect(0, 63, 144, 168), GTextAlignmentLeft, 1); fourth_word_t = text_layer_init(GRect(0, 91, 144, 168), GTextAlignmentLeft, 1); slot_t = text_layer_init(GRect(0, 130, 144, 168), GTextAlignmentLeft, 3); seconds_t = text_layer_init(GRect(115, 0, 20, 20), GTextAlignmentRight, 4); battery_bar_layer = layer_create(GRect(0, 0, 144, 168)); layer_set_update_proc(battery_bar_layer, battery_bar_proc); layer_add_child(window_layer, text_layer_get_layer(first_word_t)); layer_add_child(window_layer, text_layer_get_layer(second_word_t)); layer_add_child(window_layer, text_layer_get_layer(third_word_t)); layer_add_child(window_layer, text_layer_get_layer(fourth_word_t)); layer_add_child(window_layer, text_layer_get_layer(slot_t)); layer_add_child(window_layer, text_layer_get_layer(seconds_t)); layer_add_child(window_layer, battery_bar_layer); layer_add_child(window_layer, inverter_layer_get_layer(theme)); notify_bar_create(window); tick_timer_service_subscribe(SECOND_UNIT, tick_handler); battery_state_service_subscribe(battery_handler); bluetooth_connection_service_subscribe(bluetooth_handler); BatteryChargeState state = battery_state_service_peek(); battery_handler(state); struct tm *t; time_t temp; temp = time(NULL); t = localtime(&temp); tick_handler(t, 0); refresh_settings(); }
static void main_window_load(Window *window) { s_time_layer = text_layer_create(GRect(0, 50, 144, 50)); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_time_layer, GColorBlack); text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49)); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer)); s_date_layer = text_layer_create(GRect(0, 100, 144, 50)); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_text_color(s_date_layer, GColorBlack); text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer)); s_battery_layer = text_layer_create(GRect(0, 0, 144, 25)); text_layer_set_background_color(s_battery_layer, GColorClear); text_layer_set_text_color(s_battery_layer, GColorBlack); text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_battery_layer, GTextAlignmentRight); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_battery_layer)); battery_handler(battery_state_service_peek()); s_bt_layer = text_layer_create(GRect(0, 0, 144, 25)); text_layer_set_background_color(s_bt_layer, GColorClear); text_layer_set_text_color(s_bt_layer, GColorBlack); text_layer_set_font(s_bt_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_bt_layer, GTextAlignmentLeft); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_bt_layer)); bt_handler(bluetooth_connection_service_peek()); s_day_layer = text_layer_create(GRect(0, 150, 144, 50)); text_layer_set_background_color(s_day_layer, GColorClear); text_layer_set_text_color(s_day_layer, GColorBlack); text_layer_set_font(s_day_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text_alignment(s_day_layer, GTextAlignmentCenter); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_day_layer)); }
static void main_window_load(Window *window) { // Initialize variables. selected_color = 0; // Set background color. window_set_background_color(s_main_window, GColorFromHEX(background_colors[selected_color])); // Create background canvas. s_canvas = layer_create(GRect(0, 0, 144, 168)); // Create watch texts. s_time_layer = text_layer_create(GRect(0, 30, 144, 54)); s_info_layer = text_layer_create(GRect(10, 134, 124, 24)); // Setup watch text colors. text_layer_set_text_color(s_time_layer, GColorBlack); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_text_color(s_info_layer, GColorBlack); text_layer_set_background_color(s_info_layer, GColorClear); // Setup font for watch. s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTICON_42)); text_layer_set_font(s_time_layer, s_time_font); text_layer_set_font(s_info_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); // Set text alignments. text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); text_layer_set_text_alignment(s_info_layer, GTextAlignmentCenter); // Add it as a child layer to the Window's root layer layer_add_child(window_get_root_layer(window), s_canvas); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_info_layer)); // Get the current battery level battery_handler(battery_state_service_peek()); }
static void time_handler(struct tm* tick_time, TimeUnits units_changed) { static char time_text[] = "00:00"; // Needs to be static because it's used by the system later. static char date_text[] = "Xxxxxxxxxxx Xxxxxxxxxx 00"; static char date_num[] = "00000000"; char *time_format; strftime(date_text, sizeof(date_text), "%A, %b %e", tick_time); text_layer_set_text(date_layer, date_text); if(clock_is_24h_style()) { time_format = "%R"; } else { time_format = "%I:%M"; } strftime(time_text, sizeof(time_text), time_format, tick_time); // Kludge to handle lack of non-padded hour format string // for twelve hour clock. if (!clock_is_24h_style() && (time_text[0] == '0')) { memmove(time_text, &time_text[1], sizeof(time_text) - 1); } text_layer_set_text(time_layer, time_text); battery_handler(battery_state_service_peek()); strftime(date_num, sizeof(date_num), "%Y%m%d", tick_time); if(time(NULL) - start >= 300 || time(NULL) - start == 0) { get_events_handler(date_num); time(&start); } }
bool OSystem_PalmBase::pollEvent(Event &event) { ::EventType ev; Boolean handled; UInt32 keyCurrentState; Coord x, y; battery_handler(); timer_handler(); sound_handler(); for(;;) { #if defined(COMPILE_OS5) && defined(PALMOS_ARM) SysEventGet(&ev, evtNoWait); #else EvtGetEvent(&ev, evtNoWait); #endif // check for hardkey repeat for mouse emulation keyCurrentState = KeyCurrentState(); // check_hard_keys(); if (!(keyCurrentState & _keyMouseMask)) { _lastKeyRepeat = 0; } else { if (getMillis() >= (_keyMouseRepeat + _keyMouseDelay)) { _keyMouseRepeat = getMillis(); if (gVars->arrowKeys) { if (keyCurrentState & _keyMouse.bitUp) event.kbd.keycode = 273; else if (keyCurrentState & _keyMouse.bitDown) event.kbd.keycode = 274; else if (keyCurrentState & _keyMouse.bitLeft) event.kbd.keycode = 276; else if (keyCurrentState & _keyMouse.bitRight) event.kbd.keycode = 275; else if (keyCurrentState & _keyMouse.bitButLeft) event.kbd.keycode = chrLineFeed; event.type = EVENT_KEYDOWN; event.kbd.ascii = event.kbd.keycode; event.kbd.flags = 0; } else { Int8 sx = 0; Int8 sy = 0; if (keyCurrentState & _keyMouse.bitUp) sy = -1; else if (keyCurrentState & _keyMouse.bitDown) sy = +1; if (keyCurrentState & _keyMouse.bitLeft) sx = -1; else if (keyCurrentState & _keyMouse.bitRight) sx = +1; if (sx || sy) { simulate_mouse(event, sx, sy, &x, &y); event.type = EVENT_MOUSEMOVE; _lastKey = kKeyMouseMove; } else { x = _mouseCurState.x; y = _mouseCurState.y; if (keyCurrentState & _keyMouse.bitButLeft) { event.type = EVENT_LBUTTONDOWN; _lastKey = kKeyMouseLButton; } else if (_lastKey == kKeyMouseLButton) { event.type = EVENT_LBUTTONUP; _lastKey = kKeyNone; } } event.mouse.x = x; event.mouse.y = y; warpMouse(x, y); // updateCD(); } return true; } } if (ev.eType == keyDownEvent) { switch (ev.data.keyDown.chr) { // ESC key case vchrLaunch: _lastKey = kKeyNone; event.type = EVENT_KEYDOWN; event.kbd.keycode = 27; event.kbd.ascii = 27; event.kbd.flags = 0; return true; // F5 = menu case vchrMenu: _lastKey = kKeyNone; event.type = EVENT_KEYDOWN; event.kbd.keycode = 319; event.kbd.ascii = 319; event.kbd.flags = 0; return true; // if hotsync pressed, etc... case vchrHardCradle: case vchrHardCradle2: case vchrLowBattery: case vchrFind: // case vchrBrightness: // volume control on Zodiac, let other backends disable it case vchrContrast: // do nothing _lastKey = kKeyNone; return true; } } if (check_event(event, &ev)) return true; _lastKey = kKeyNone; // prevent crash when alarm is raised handled = ((ev.eType == keyDownEvent) && (ev.data.keyDown.modifiers & commandKeyMask) && ((ev.data.keyDown.chr == vchrAttnStateChanged) || (ev.data.keyDown.chr == vchrAttnUnsnooze))); // graffiti strokes, auto-off, etc... if (!handled) if (SysHandleEvent(&ev)) continue; switch(ev.eType) { case penMoveEvent: get_coordinates(&ev, x, y); if (y > _screenHeight || y < 0 || x > _screenWidth || x < 0) return false; if (_lastEvent != penMoveEvent && (abs(y - event.mouse.y) <= 2 || abs(x - event.mouse.x) <= 2)) // move only if return false; _lastEvent = penMoveEvent; event.type = EVENT_MOUSEMOVE; event.mouse.x = x; event.mouse.y = y; warpMouse(x, y); return true; case penDownEvent: get_coordinates(&ev, x, y); // indy fight mode if (_useNumPad && !_overlayVisible) { char num = '1'; num += 9 - (3 - (3 * x / _screenWidth )) - (3 * (3 * y / _screenHeight)); event.type = EVENT_KEYDOWN; event.kbd.keycode = num; event.kbd.ascii = num; event.kbd.flags = 0; _lastEvent = keyDownEvent; return true; } _lastEvent = penDownEvent; if (y > _screenHeight || y < 0 || x > _screenWidth || x < 0) return false; event.type = ((gVars->stylusClick || _overlayVisible) ? EVENT_LBUTTONDOWN : EVENT_MOUSEMOVE); event.mouse.x = x; event.mouse.y = y; warpMouse(x, y); return true; case penUpEvent: get_coordinates(&ev, x, y); event.type = ((gVars->stylusClick || _overlayVisible) ? EVENT_LBUTTONUP : EVENT_MOUSEMOVE); if (y > _screenHeight || y < 0 || x > _screenWidth || x < 0) return false; event.mouse.x = x; event.mouse.y = y; warpMouse(x, y); return true; case keyDownEvent: if (ev.data.keyDown.chr == vchrCommand && (ev.data.keyDown.modifiers & commandKeyMask)) { _lastKeyModifier++; _lastKeyModifier %= kModifierCount; if (_lastKeyModifier) draw_osd((kDrawKeyState + _lastKeyModifier - 1), 2, _screenDest.h + 2, true); else draw_osd(kDrawKeyState, 2, _screenDest.h + 2, false); return false; } char mask = 0; UInt16 key = ev.data.keyDown.chr; if (_lastKeyModifier == kModifierNone) { // for keyboard mode if (ev.data.keyDown.modifiers & shiftKeyMask) mask |= KBD_SHIFT; if (ev.data.keyDown.modifiers & controlKeyMask) mask |= KBD_CTRL; if (ev.data.keyDown.modifiers & optionKeyMask) mask |= KBD_ALT; if (ev.data.keyDown.modifiers & commandKeyMask) mask |= KBD_CTRL|KBD_ALT; } else { // for grafiti mode if (_lastKeyModifier == kModifierCommand) mask = KBD_CTRL|KBD_ALT; if (_lastKeyModifier == kModifierAlt) mask = KBD_ALT; if (_lastKeyModifier == kModifierCtrl) mask = KBD_CTRL; } if (_lastKeyModifier) draw_osd(kDrawKeyState, 2, _screenDest.h + 2, false); _lastKeyModifier = kModifierNone; // F1 -> F10 key if (key >= '0' && key <= '9' && mask == (KBD_CTRL|KBD_ALT)) { key = (key == '0') ? 324 : (315 + key - '1'); mask = 0; // exit } else if ((key == 'z' && mask == KBD_CTRL) || (mask == KBD_ALT && key == 'x')) { event.type = EVENT_QUIT; return true; // num pad (indy fight mode) } else if (key == 'n' && mask == (KBD_CTRL|KBD_ALT) && !_overlayVisible) { _useNumPad = !_useNumPad; draw_osd(kDrawFight, _screenDest.w - 34, _screenDest.h + 2, _useNumPad, 1); displayMessageOnOSD(_useNumPad ? "Fight mode on." : "Fight mode off."); return false; } // other keys event.type = EVENT_KEYDOWN; event.kbd.keycode = key; event.kbd.ascii = key; event.kbd.flags = mask; return true; default: return false; }; } }
static void window_load(Window* window) { // Handle the settings. #ifdef PBL_COLOR // Set default colors. mLightColor = GColorCeleste; mMediumColor = GColorJaegerGreen; mDarkColor = GColorDarkGreen; mBackgroundColor = GColorBlack; // Try to get saved colors. // Colors are auto mapped to the nearest color out of 64 available. APP_LOG(APP_LOG_LEVEL_DEBUG, "KEY_COLOR_ 1"); if (persist_exists(KEY_COLOR_RED1) && persist_exists(KEY_COLOR_GREEN1) && persist_exists(KEY_COLOR_BLUE1)) { int red = persist_read_int(KEY_COLOR_RED1); int green = persist_read_int(KEY_COLOR_GREEN1); int blue = persist_read_int(KEY_COLOR_BLUE1); mDarkColor = GColorFromRGB(red, green, blue); } APP_LOG(APP_LOG_LEVEL_DEBUG, "KEY_COLOR_ 2"); if (persist_exists(KEY_COLOR_RED2) && persist_exists(KEY_COLOR_GREEN2) && persist_exists(KEY_COLOR_BLUE2)) { int red = persist_read_int(KEY_COLOR_RED2); int green = persist_read_int(KEY_COLOR_GREEN2); int blue = persist_read_int(KEY_COLOR_BLUE2); mLightColor = GColorFromRGB(red, green, blue); } #else /*APP_LOG(APP_LOG_LEVEL_DEBUG, "KEY_INVERT"); if (persist_exists(KEY_INVERT)) { mIsInverted = persist_read_bool(KEY_INVERT); APP_LOG(APP_LOG_LEVEL_DEBUG, "KEY_INVERT: %d", mIsInverted); } if (mIsInverted) { mBackgroundColor = GColorWhite; mTextColor = GColorBlack; } else*/ { mBackgroundColor = GColorBlack; mTextColor = GColorWhite; } #endif // PBL_COLOR mIs24HourStyle = clock_is_24h_style(); APP_LOG(APP_LOG_LEVEL_DEBUG, "mIs24HourStyle: %d", mIs24HourStyle); APP_LOG(APP_LOG_LEVEL_DEBUG, "window_load: set_background"); window_set_background_color(window, mBackgroundColor); APP_LOG(APP_LOG_LEVEL_DEBUG, "window_load: add layers"); sBgLayer = layer_create(GRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)); layer_set_update_proc(sBgLayer, (LayerUpdateProc)render_bg); layer_add_child(window_get_root_layer(window), sBgLayer); sTimeLayer = layer_create(GRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)); layer_set_update_proc(sTimeLayer, (LayerUpdateProc)render_time); layer_add_child(window_get_root_layer(window), sTimeLayer); APP_LOG(APP_LOG_LEVEL_DEBUG, "window_load: setup fonts"); mDayFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_CONSOLAB_14)); mTimeFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DSEG_BOLD_30)); mTimeFontSmall = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DSEG_BOLD_16)); mDateFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DSEG_NORMAL_14)); //mDateFontSmall = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DSEG_NORMAL_10)); mDayText = malloc(9+1); // WEDNESDAY mTimeText = malloc(5+1); // HH:MM mTopText = malloc(5+1); // P T T mDateText = malloc(5+1); // MM.DD APP_LOG(APP_LOG_LEVEL_DEBUG, "window_load: set time"); struct tm* t; time_t temp; temp = time(NULL); t = localtime(&temp); set_time_display(t); // Init the BT and battery indicators. APP_LOG(APP_LOG_LEVEL_DEBUG, "window_load: setup bt and battery"); bt_handler(bluetooth_connection_service_peek()); battery_handler(battery_state_service_peek()); }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); battery_layer = layer_create(GRect(0, 0, 144, 30)); outline_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_LECO_16)); bluetooth_connection_service_subscribe(bluetooth_handler); upper_text_layer = text_layer_create(GRect(0, 36, 144, 44)); text_layer_set_font(upper_text_layer, fonts_get_system_font(FONT_KEY_LECO_42_NUMBERS)); text_layer_set_text_alignment(upper_text_layer, GTextAlignmentCenter); text_layer_set_background_color(upper_text_layer, GColorClear); outline_layer = text_layer_create(GRect(0, 36, 144, 168)); text_layer_set_font(outline_layer, outline_font); text_layer_set_text_alignment(outline_layer, GTextAlignmentCenter); text_layer_set_text_color(outline_layer, GColorWhite); text_layer_set_background_color(outline_layer, GColorClear); lower_text_layer = text_layer_create(GRect(0, 84, 144, 100)); text_layer_set_font(lower_text_layer, fonts_get_system_font(FONT_KEY_LECO_28_LIGHT_NUMBERS)); text_layer_set_text_alignment(lower_text_layer, GTextAlignmentCenter); text_layer_set_background_color(lower_text_layer, GColorClear); text_layer_set_text(lower_text_layer, ""); weekday_text = text_layer_create(GRect(0,144,144,25)); text_layer_set_text_alignment(weekday_text, GTextAlignmentCenter); text_layer_set_background_color(weekday_text, GColorClear); text_layer_set_text_color(weekday_text, GColorWhite); text_layer_set_font(weekday_text, outline_font); battery_text = text_layer_create(GRect(0,0,144,25)); text_layer_set_text_alignment(battery_text, GTextAlignmentCenter); text_layer_set_background_color(battery_text, GColorClear); text_layer_set_text_color(battery_text, GColorWhite); text_layer_set_font(battery_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); layer_add_child(window_layer, battery_layer); layer_add_child(window_layer, text_layer_get_layer(lower_text_layer)); layer_add_child(window_layer, text_layer_get_layer(upper_text_layer)); layer_add_child(window_layer, text_layer_get_layer(outline_layer)); layer_add_child(battery_layer, text_layer_get_layer(battery_text)); layer_add_child(window_layer, text_layer_get_layer(weekday_text)); if (persist_read_int(KEY_TOP_COLOR)) { int top_color = persist_read_int(KEY_TOP_COLOR); set_background_and_text_color(top_color); } if (persist_read_int(KEY_BOTTOM_COLOR)) { int bottom_color = persist_read_int(KEY_BOTTOM_COLOR); set_layer1_color_and_text(bottom_color); } if (persist_read_bool(KEY_TWENTY_FOUR_HOUR_FORMAT)) { twenty_four_hour_format = persist_read_bool(KEY_TWENTY_FOUR_HOUR_FORMAT); } if (persist_read_int(KEY_TOP_TEXT_COLOR)) { int top_text_color = persist_read_int(KEY_TOP_TEXT_COLOR); set_top_text_color(top_text_color); } if(persist_read_int(KEY_BOTTOM_TEXT_COLOR)) { int bottom_text_color = persist_read_int(KEY_BOTTOM_TEXT_COLOR); set_bottom_text_color(bottom_text_color); } if(persist_exists(KEY_BLUETOOTH_VIBRATION)){ bluetooth_vibration = persist_read_int(KEY_BLUETOOTH_VIBRATION); APP_LOG(APP_LOG_LEVEL_INFO,"Bluetooth read"); } if(persist_exists(KEY_SHOW_BATTERY)){ show_battery = persist_read_int(KEY_SHOW_BATTERY); } if(persist_exists(KEY_SHOW_WEEKDAY)){ show_weekday = persist_read_int(KEY_SHOW_WEEKDAY); APP_LOG(APP_LOG_LEVEL_INFO,"Weekday read"); } if(persist_exists(KEY_DATE_FORMAT)){ change_date_format = persist_read_int(KEY_DATE_FORMAT); APP_LOG(APP_LOG_LEVEL_INFO,"Date format read"); } if(persist_read_int(KEY_WEEKDAY_COLOR)) { int weekday_color = persist_read_int(KEY_WEEKDAY_COLOR); set_weekday_color(weekday_color); } if(persist_read_int(KEY_BATTERY_COLOR)) { int battery_color = persist_read_int(KEY_BATTERY_COLOR); set_battery_color(battery_color); } if(persist_read_bool(KEY_HOUR_VIBRATE)) { hour_vibrate = persist_read_bool(KEY_HOUR_VIBRATE); } update_time(); update_layers(); battery_handler(battery_state_service_peek()); }
static void main_window_load(Window *window) { windowMain = window; // Create time TextLayer s_hr_layer = text_layer_create(GRect(0, 10, 126, 50)); text_layer_set_background_color(s_hr_layer, GColorClear); text_layer_set_text_color(s_hr_layer, GColorBlack); text_layer_set_text(s_hr_layer, "#00"); s_min_layer = text_layer_create(GRect(0, 45, 155, 50)); text_layer_set_background_color(s_min_layer, GColorClear); text_layer_set_text_color(s_min_layer, GColorBlack); text_layer_set_text(s_min_layer, "00"); s_sec_layer = text_layer_create(GRect(0, 80, 155, 50)); text_layer_set_background_color(s_sec_layer, GColorClear); text_layer_set_text_color(s_sec_layer, GColorBlack); text_layer_set_text(s_sec_layer, ""); s_date_layer = text_layer_create(GRect(0, 145, 144, 25)); text_layer_set_background_color(s_date_layer, GColorWhite); text_layer_set_text_color(s_date_layer, GColorClear); text_layer_set_text(s_date_layer, "0000"); s_battery_layer = text_layer_create(GRect(4, 145, 144, 25)); text_layer_set_background_color(s_battery_layer, GColorClear); text_layer_set_text_color(s_battery_layer, GColorClear); text_layer_set_text(s_battery_layer, "00%"); s_color_name_layer = text_layer_create(GRect(0,0,144,25)); text_layer_set_background_color(s_color_name_layer, GColorWhite); // Improve the layout to be more like a watchface text_layer_set_font(s_hr_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BLOCK_42))); text_layer_set_text_alignment(s_hr_layer, GTextAlignmentCenter); text_layer_set_text_color(s_hr_layer, GColorWhite); text_layer_set_font(s_min_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BLOCK_42))); text_layer_set_text_alignment(s_min_layer, GTextAlignmentCenter); text_layer_set_text_color(s_min_layer, GColorWhite); text_layer_set_font(s_sec_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BLOCK_42))); text_layer_set_text_alignment(s_sec_layer, GTextAlignmentCenter); text_layer_set_text_color(s_sec_layer, GColorWhite); text_layer_set_font(s_date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BLOCK_20))); text_layer_set_text_alignment(s_date_layer, GTextAlignmentRight); text_layer_set_text_color(s_date_layer, GColorWhite); text_layer_set_font(s_battery_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BLOCK_20))); text_layer_set_text_alignment(s_battery_layer, GTextAlignmentLeft); text_layer_set_text_color(s_battery_layer, GColorWhite); // Add it as a child layer to the Window's root layer layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_hr_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_min_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_sec_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_battery_layer)); // Get the current battery level battery_handler(battery_state_service_peek()); // Make sure the time is displayed from the start update_time(); }
static void main_window_load(Window *window) { //Create background bitmap, then set to created BitmapLayer s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_DEDSEC_LOGO); s_background_layer = bitmap_layer_create(GRect(0, 0, 144, 168)); bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_background_layer)); //Create BT bitmap, then set to created BitmapLayer s_bluetooth_bitmap = gbitmap_create_with_resource(RESOURCE_ID_SIGNAL); s_bluetooth_layer = bitmap_layer_create(GRect(0, 144, 20, 20)); bitmap_layer_set_bitmap(s_bluetooth_layer, s_bluetooth_bitmap); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_bluetooth_layer)); //Create Battery bitmap, then set to created BitmapLayer s_battery_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_CHARGING); s_battery_layer = bitmap_layer_create(GRect(122, 123, 22, 18)); bitmap_layer_set_bitmap(s_battery_layer, s_battery_bitmap); layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_battery_layer)); // Create time TextLayer s_hour_layer = text_layer_create(GRect(0, -5, 60, 84)); text_layer_set_background_color(s_hour_layer, GColorClear); text_layer_set_text_color(s_hour_layer, GColorWhite); text_layer_set_text(s_hour_layer, "00"); s_minute_layer = text_layer_create(GRect(0, 55, 60, 84)); text_layer_set_background_color(s_minute_layer, GColorClear); text_layer_set_text_color(s_minute_layer, GColorWhite); text_layer_set_text(s_minute_layer, "00"); //Create GFont s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_WATCHDOGS_SUBSET_58)); //Apply to TextLayer text_layer_set_font(s_hour_layer, s_time_font); text_layer_set_text_alignment(s_hour_layer, GTextAlignmentCenter); text_layer_set_font(s_minute_layer, s_time_font); text_layer_set_text_alignment(s_minute_layer, GTextAlignmentCenter); // Add it as a child layer to the Window's root layer layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_hour_layer)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_minute_layer)); //Create date text layer s_date_layer = text_layer_create(GRect(0, 150, 144, 18)); text_layer_set_background_color(s_date_layer, GColorClear); text_layer_set_text_color(s_date_layer, GColorWhite); text_layer_set_text(s_date_layer, "MON_01_01_2001"); text_layer_set_text_alignment(s_date_layer, GTextAlignmentRight); text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_layer)); //Create connection background layer s_connection_bg_layer = text_layer_create(GRect(0, 123, 122, 18)); #ifdef PBL_COLOR text_layer_set_background_color(s_connection_bg_layer, GColorTiffanyBlue); #else text_layer_set_background_color(s_connection_bg_layer, GColorClear); #endif text_layer_set_text_color(s_connection_bg_layer, GColorWhite); text_layer_set_text(s_connection_bg_layer, CONNECTION_TEXT); text_layer_set_font(s_connection_bg_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_connection_bg_layer)); //Create connection text layer s_connection_layer = text_layer_create(GRect(0, 123, 122, 18)); text_layer_set_text(s_connection_layer, CONNECTION_TEXT); s_connection_bar_color = GColorWhite; layer_set_update_proc((Layer*) s_connection_layer, text_update_proc); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_connection_layer)); //Create hacking text layer s_hacking_layer = text_layer_create(GRect(0, 137, 144, 18)); text_layer_set_background_color(s_hacking_layer, GColorClear); text_layer_set_text_color(s_hacking_layer, GColorWhite); text_layer_set_text(s_hacking_layer, "_hacking is our weapon"); text_layer_set_text_alignment(s_hacking_layer, GTextAlignmentRight); text_layer_set_font(s_hacking_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_hacking_layer)); // Make sure the time is displayed from the start update_time(); // Show current connection state bt_handler(bluetooth_connection_service_peek()); // Show current battery state battery_handler(battery_state_service_peek()); }