Skip to content

Commit

Permalink
Add notifications for BT msg, alert, battery and mini messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ginge committed Feb 26, 2018
1 parent 1ea7f5f commit e41c87d
Show file tree
Hide file tree
Showing 23 changed files with 1,074 additions and 196 deletions.
98 changes: 82 additions & 16 deletions Apps/System/notification.c
@@ -1,8 +1,9 @@
/* notification.h
* routines for [...]
/* notification.c
* An app for displaying notification messages
* RebbleOS
*
* Author: Carson Katri <me@carsonkatri.com>
* Barry Carter <barry.carter@gmail.com>
*/

#include "rebbleos.h"
Expand All @@ -12,12 +13,19 @@
#include "bitmap_layer.h"
#include "action_bar_layer.h"
#include "platform_res.h"
#include "menu.h"
#include "protocol_notification.h"
#include "notification_manager.h"

static NotificationLayer* _notif_layer;
static Window* _notif_window;
static Menu *s_menu;
static Window *s_main_window;

static void _notif_window_load(Window *window);
static void _notif_window_unload(Window *window);
static void _exit_to_watchface(struct Menu *menu, void *context);
static void _notif_destroy_layer_cb(ClickRecognizerRef _, void *context);

void notif_init(void)
{
Expand All @@ -31,29 +39,81 @@ void notif_init(void)
window_stack_push(_notif_window, true);
}

static void _notif_window_load(Window *window)
static MenuItems* _msg_list_item_selected(const MenuItem *item)
{
char *app = "RebbleOS";
char *title = "Test Alert";
char *body = "Testing a basic notification on RebbleOS. Create it using notification_window_create, with an app_name, title, body, and optional icon.";
char *title = "Message";
full_msg_t *msg = (full_msg_t *)item->context;

Layer *layer = window_get_root_layer(window);
GRect bounds = layer_get_unobstructed_bounds(layer);
cmd_phone_attribute_t *attr = list_elem(list_get_head(&msg->attributes_list_head), cmd_phone_attribute_t, node);

Layer *layer = window_get_root_layer(s_main_window);
GRect bounds = layer_get_unobstructed_bounds(layer);
_notif_layer = notification_layer_create(bounds);
Notification *notification = notification_create(app, title, body, gbitmap_create_with_resource(RESOURCE_ID_UNKNOWN), GColorRed);

Notification *notification = notification_create(app, title, (const char *)attr->data, gbitmap_create_with_resource(RESOURCE_ID_SPEECH_BUBBLE), GColorRed);
notification_layer_stack_push_notification(_notif_layer, notification);

Notification *notification_two = notification_create("Discord", "Join Us", "Join us on the Pebble Discord in the #firmware channel", gbitmap_create_with_resource(RESOURCE_ID_ALARM_BELL_RINGING), GColorFromRGB(85, 0, 170));
notification_layer_stack_push_notification(_notif_layer, notification_two);

notification_layer_configure_click_config(_notif_layer, s_main_window, _notif_destroy_layer_cb);
layer_add_child(layer, notification_layer_get_layer(_notif_layer));

notification_layer_configure_click_config(_notif_layer, window);


layer_mark_dirty(layer);
window_dirty(true);

return NULL;
}

static void _notif_destroy_layer_cb(ClickRecognizerRef _, void *context)
{
notification_layer_destroy(_notif_layer);
menu_set_click_config_onto_window(s_menu, s_main_window);
window_load_click_config(s_main_window);
}

static void _notif_window_load(Window *window)
{
s_main_window = window;
Layer *window_layer = window_get_root_layer(window);
MenuItems *items;

#ifdef PBL_RECT
s_menu = menu_create(GRect(0, 16, DISPLAY_COLS, DISPLAY_ROWS - 16));
#else
// Let the menu draw behind the statusbar so it is perfectly centered
s_menu = menu_create(GRect(0, 0, DISPLAY_COLS, DISPLAY_ROWS));
#endif
menu_set_callbacks(s_menu, s_menu, (MenuCallbacks) {
.on_menu_exit = _exit_to_watchface
});
layer_add_child(window_layer, menu_get_layer(s_menu));

menu_set_click_config_onto_window(s_menu, window);
if (!message_count())
{
items = menu_items_create(1);
menu_items_add(items, MenuItem("No Messages", NULL, RESOURCE_ID_SPEECH_BUBBLE, NULL));
menu_set_items(s_menu, items);
return;
}

items = menu_items_create(message_count());
full_msg_t *msg;
cmd_phone_attribute_t *a;
list_head *message_head = message_get_head();

list_foreach(msg, message_head, full_msg_t, node)
{
list_foreach(a, &msg->attributes_list_head, cmd_phone_attribute_t, node)
{
MenuItem mi = MenuItem((char *)a->data, NULL, RESOURCE_ID_SPEECH_BUBBLE, _msg_list_item_selected);
mi.context = msg;
menu_items_add(items, mi);
}
}
menu_set_items(s_menu, items);


return;

}

static void _notif_window_unload(Window *window)
Expand All @@ -77,3 +137,9 @@ void notif_main(void)
app_event_loop();
notif_deinit();
}

static void _exit_to_watchface(struct Menu *menu, void *context)
{
// Exit to watchface
appmanager_app_start("Simple");
}
11 changes: 5 additions & 6 deletions Apps/System/systemapp.c
Expand Up @@ -14,8 +14,6 @@

extern void flash_dump(void);

const char *systemapp_name = "System";

static Window *s_main_window;
static Menu *s_menu;

Expand All @@ -42,7 +40,7 @@ static MenuItems* app_item_selected(const MenuItem *item)
return NULL;
}

static MenuItems* test_item_selected(const MenuItem *item)
static MenuItems* settings_item_selected(const MenuItem *item)
{
appmanager_app_start("Settings");
return NULL;
Expand Down Expand Up @@ -102,11 +100,12 @@ static void systemapp_window_load(Window *window)

menu_set_click_config_onto_window(s_menu, window);

MenuItems *items = menu_items_create(4);
MenuItems *items = menu_items_create(5);
menu_items_add(items, MenuItem("Watchfaces", "All your faces", RESOURCE_ID_CLOCK, watch_list_item_selected));
menu_items_add(items, MenuItem("Settings", "Move Along", RESOURCE_ID_SPANNER, test_item_selected));
menu_items_add(items, MenuItem("Settings", "Config", RESOURCE_ID_SPANNER, settings_item_selected));
menu_items_add(items, MenuItem("Tests", NULL, RESOURCE_ID_CLOCK, run_test_item_selected));
menu_items_add(items, MenuItem("RebbleOS", "... v0.0.0.1", RESOURCE_ID_SPEECH_BUBBLE, NULL));
menu_items_add(items, MenuItem("Notifications", NULL, RESOURCE_ID_SPEECH_BUBBLE, notification_item_selected));
menu_items_add(items, MenuItem("RebbleOS", "... v0.0.0.2", RESOURCE_ID_SPEECH_BUBBLE, NULL));
menu_set_items(s_menu, items);

#ifdef PBL_RECT
Expand Down
57 changes: 33 additions & 24 deletions Apps/System/tests/overlay_test.c
Expand Up @@ -23,11 +23,13 @@ static OverlayWindow *_overlay_window;
static OverlayWindow *_overlay_window2;
static OverlayWindow *_overlay_window3;
static void _color_test_layer_update_proc(Layer *layer, GContext *ctx);
static void _creation_callback(OverlayWindow *overlay_window);
static void _creation_callback2(OverlayWindow *overlay_window);
static void _creation_callback(OverlayWindow *overlay_window, Window *window);
static void _creation_callback2(OverlayWindow *overlay_window, Window *window);
void _ovl_tick(struct tm *tick_time, TimeUnits tick_units);
static void _test_layer_update_proc(Layer *layer, GContext *nGContext);
static void _notif_init(OverlayWindow *overlay_window);
static void _notif_init(OverlayWindow *overlay_window, Window *window);
static void _notif_test_window_load(Window *window);
static void _notif_test_window_unload(Window *window);
bool _notif_deinit(void);

static int _total_elapsed;
Expand Down Expand Up @@ -114,9 +116,6 @@ bool _test_notif_destroy_test(NotificationLayer **ol, OverlayWindow **ow, GPoint
{
switch(_sub_stage) {
case 0:
if (*ol)
notification_layer_destroy(*ol);
*ol = NULL;
overlay_window_destroy(*ow);
*ow = NULL;
_sub_stage = 1;
Expand All @@ -138,7 +137,7 @@ bool _test_overlay_notif_destroy()
switch(ss) {
case 0:
test_assert_point_is_color(GPoint(10,10), GColorFromRGB(85, 0, 170));
_notif_deinit();
// _notif_deinit();
ss = 1;
return false;
case 1:
Expand Down Expand Up @@ -310,13 +309,13 @@ static void _overlayer_update(Layer *layer, GContext *ctx)
graphics_fill_rect(ctx, GRect(10, 10, 50, 50), 0, GCornerNone);
}

static void _creation_callback(OverlayWindow *overlay_window)
static void _creation_callback(OverlayWindow *overlay_window, Window *window)
{
SYS_LOG("overlay", APP_LOG_LEVEL_INFO, "Overlay Create CB");
_overlay_window = overlay_window;
Window *window = window_create();

window->background_color = GColorClear;
overlay_window_stack_push_window(_overlay_window, window, false);

Layer *window_layer = window_get_root_layer(window);
GRect bounds = layer_get_unobstructed_bounds(window_layer);
_overlay_layer = layer_create(bounds);
Expand All @@ -337,12 +336,11 @@ static void _overlayer_update2(Layer *layer, GContext *ctx)
graphics_fill_rect(ctx, GRect(0, DISPLAY_ROWS - 50, DISPLAY_COLS, 50), 0, GCornerNone);
}

static void _creation_callback2(OverlayWindow *overlay_window)
static void _creation_callback2(OverlayWindow *overlay_window, Window *window)
{
_overlay_window2 = overlay_window;
Window *window = window_create();
window->background_color = GColorClear;
overlay_window_stack_push_window(_overlay_window2, window, false);

Layer *window_layer = window_get_root_layer(window);
GRect bounds = layer_get_unobstructed_bounds(window_layer);
_overlay_layer2 = layer_create(bounds);
Expand All @@ -360,37 +358,48 @@ static void _creation_callback2(OverlayWindow *overlay_window)

// static NotificationWindow *notif_window;

static void _notif_init(OverlayWindow *overlay_window)
static void _notif_init(OverlayWindow *overlay_window, Window *window)
{
_overlay_window3 = overlay_window;
window_set_window_handlers(window, (WindowHandlers) {
.load = _notif_test_window_load,
.unload = _notif_test_window_unload,
});

}

bool _notif_deinit(void)
{
_overlay_window3 = overlay_window;
return true;
}

static void _notif_test_window_load(Window *window)
{
char *app = "RebbleOS";
char *title = "Test Alert";
char *body = "Testing a basic notification on RebbleOS. Create it using notification_window_create, with an app_name, title, body, and optional icon.";
Window *window = window_create();
window->background_color = GColorClear;
overlay_window_stack_push_window(_overlay_window3, window, false);

Layer *layer = window_get_root_layer(window);

Layer *layer = window_get_root_layer(window);
GRect bounds = layer_get_unobstructed_bounds(layer);

_notif_layer = notification_layer_create(bounds);
Notification *notification = notification_create(app, title, body, gbitmap_create_with_resource(RESOURCE_ID_UNKNOWN), GColorRed);
Notification *notification = notification_create(app, title, body, gbitmap_create_with_resource(RESOURCE_ID_SPEECH_BUBBLE), GColorRed);

notification_layer_stack_push_notification(_notif_layer, notification);

Notification *notification_two = notification_create("Discord", "Join Us", "Join us on the Pebble Discord in the #firmware channel", gbitmap_create_with_resource(RESOURCE_ID_ALARM_BELL_RINGING), GColorFromRGB(85, 0, 170));
notification_layer_stack_push_notification(_notif_layer, notification_two);

layer_add_child(layer, notification_layer_get_layer(_notif_layer));
notification_layer_configure_click_config(_notif_layer, window, NULL);
overlay_window_stack_push(_overlay_window3, true);

notification_layer_configure_click_config(_notif_layer, window);
overlay_window_stack_push(overlay_window, true);
layer_mark_dirty(layer);
window_dirty(true);
}

bool _notif_deinit(void)
static void _notif_test_window_unload(Window *window)
{
notification_layer_destroy(_notif_layer);
return true;
}
6 changes: 6 additions & 0 deletions config.mk
Expand Up @@ -21,6 +21,7 @@ CFLAGS_all += -Ircore
CFLAGS_all += -Ircore/protocol
CFLAGS_all += -Irwatch
CFLAGS_all += -Irwatch/ui
CFLAGS_all += -Irwatch/ui/notifications
CFLAGS_all += -Irwatch/ui/layer
CFLAGS_all += -Irwatch/ui/animation
CFLAGS_all += -Irwatch/input
Expand Down Expand Up @@ -90,6 +91,8 @@ SRCS_all += rcore/display.c
SRCS_all += rcore/debug.c
SRCS_all += rcore/gyro.c
SRCS_all += rcore/main.c
SRCS_all += rcore/notification_manager.c
SRCS_all += rcore/notification_message.c
SRCS_all += rcore/power.c
SRCS_all += rcore/rebbleos.c
SRCS_all += rcore/smartstrap.c
Expand Down Expand Up @@ -128,6 +131,9 @@ SRCS_all += rwatch/event/app_timer.c
SRCS_all += rwatch/ui/layer/status_bar_layer.c
SRCS_all += rwatch/ui/animation/animation.c
SRCS_all += rwatch/ui/animation/property_animation.c
SRCS_all += rwatch/ui/notifications/notification_window.c
SRCS_all += rwatch/ui/notifications/battery_overlay.c
SRCS_all += rwatch/ui/notifications/mini_message.c

SRCS_all += Watchfaces/simple.c
SRCS_all += Watchfaces/nivz.c
Expand Down
2 changes: 2 additions & 0 deletions rcore/appmanager.h
Expand Up @@ -191,6 +191,8 @@ void appmanager_post_draw_message(void);
void appmanager_app_start(char *name);
void appmanager_app_quit(void);
void appmanager_post_generic_app_message(AppMessage *am, TickType_t timeout);
void appmanager_timer_expired(app_running_thread *thread);
TickType_t appmanager_timer_get_next_expiry(app_running_thread *thread);

/* in appmanager_app.c */
App *appmanager_get_app(char *app_name);
Expand Down

0 comments on commit e41c87d

Please sign in to comment.