summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2014-07-04 18:21:06 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2014-07-04 18:21:06 +0100
commit7635e18b81934dca633641efebe9ff6f6734bb62 (patch)
tree54bd5a3d56fac42be49db96d4da6e91f9d58fd0e
parent54f73a6e88864db739da0e14c0ec019b910c5bbc (diff)
downloadaskel-ja-uni-7635e18b81934dca633641efebe9ff6f6734bb62.tar.bz2
Add step/sleep indicator
-rw-r--r--watchapp/src/watchapp.c45
1 files changed, 36 insertions, 9 deletions
diff --git a/watchapp/src/watchapp.c b/watchapp/src/watchapp.c
index 7fc40f4..da93710 100644
--- a/watchapp/src/watchapp.c
+++ b/watchapp/src/watchapp.c
@@ -12,6 +12,25 @@ static ResourceId current_battery_id = INVALID_RESOURCE;
static GBitmap *current_battery_image;
static BitmapLayer *battery_layer;
+static ResourceId current_mode_id = INVALID_RESOURCE;
+static GBitmap *current_mode_image;
+static BitmapLayer *mode_layer;
+
+static void set_mode_icon()
+{
+ ResourceId target_mode_id = (monitor_mode == mmSteps) ?
+ RESOURCE_ID_ICON_STEPS : RESOURCE_ID_ICON_SLEEP;
+ GBitmap *new_image;
+ if (target_mode_id == current_mode_id)
+ return;
+ new_image = gbitmap_create_with_resource(target_mode_id);
+ bitmap_layer_set_bitmap(mode_layer, new_image);
+ if (current_mode_id != INVALID_RESOURCE)
+ gbitmap_destroy(current_mode_image);
+ current_mode_image = new_image;
+ current_mode_id = target_mode_id;
+}
+
static void handle_battery_update(BatteryChargeState charge)
{
ResourceId target_battery_id = INVALID_RESOURCE;
@@ -30,9 +49,8 @@ static void handle_battery_update(BatteryChargeState charge)
return;
new_image = gbitmap_create_with_resource(target_battery_id);
bitmap_layer_set_bitmap(battery_layer, new_image);
- if (current_battery_id != INVALID_RESOURCE) {
+ if (current_battery_id != INVALID_RESOURCE)
gbitmap_destroy(current_battery_image);
- }
current_battery_image = new_image;
current_battery_id = target_battery_id;
}
@@ -58,6 +76,7 @@ static void handle_second_tick(struct tm* tick_time, TimeUnits units_changed)
text_layer_set_text(time_layer, time_text);
text_layer_set_text(date_layer, date_text);
text_layer_set_text(step_layer, step_text);
+ set_mode_icon();
}
static void select_click_handler(ClickRecognizerRef recognizer, void *context)
@@ -105,34 +124,39 @@ static void window_load(Window *window)
text_layer_set_font(date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
// Init the text layer used to show steps
- step_layer = text_layer_create(GRect(16, 0, 65, 16));
+ step_layer = text_layer_create(GRect(16, -1, 65, 14));
text_layer_set_text_color(step_layer, GColorWhite);
text_layer_set_background_color(step_layer, GColorClear);
text_layer_set_font(date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
+ // Now prepare the status icon layers
+ battery_layer = bitmap_layer_create(GRect(120,0,24,16));
+ bitmap_layer_set_background_color(battery_layer, GColorClear);
+
+ mode_layer = bitmap_layer_create(GRect(0,0,16,16));
+ bitmap_layer_set_background_color(mode_layer, GColorClear);
+
// 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_second_tick(current_time, SECOND_UNIT);
tick_timer_service_subscribe(SECOND_UNIT, &handle_second_tick);
+ // And ensure that the battery is updated
+ handle_battery_update(battery_state_service_peek());
+ battery_state_service_subscribe(handle_battery_update);
// Finally create a simple white line
line_layer = layer_create(GRect(4, 168-49-1, 144-8, 2));
layer_set_update_proc(line_layer, draw_line);
- // Now prepare the status icon layers
- battery_layer = bitmap_layer_create(GRect(120,0,24,16));
- bitmap_layer_set_background_color(battery_layer, GColorClear);
- handle_battery_update(battery_state_service_peek());
- battery_state_service_subscribe(handle_battery_update);
-
// And stuff the layers into the window
layer_add_child(window_get_root_layer(window), text_layer_get_layer(time_layer));
layer_add_child(window_get_root_layer(window), text_layer_get_layer(date_layer));
layer_add_child(window_get_root_layer(window), text_layer_get_layer(step_layer));
layer_add_child(window_get_root_layer(window), line_layer);
layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(battery_layer));
+ layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(mode_layer));
}
static void window_unload(Window *window)
@@ -142,6 +166,9 @@ static void window_unload(Window *window)
text_layer_destroy(time_layer);
text_layer_destroy(date_layer);
text_layer_destroy(step_layer);
+ bitmap_layer_destroy(mode_layer);
+ if (current_mode_id != INVALID_RESOURCE)
+ gbitmap_destroy(current_mode_image);
bitmap_layer_destroy(battery_layer);
if (current_battery_id != INVALID_RESOURCE)
gbitmap_destroy(current_battery_image);