@@ -29,6 +29,7 @@ struct RootWindow {
2929 Window * window ;
3030 ActionBarLayer * action_bar ;
3131 SessionWindow * session_window ;
32+ GBitmap * question_icon ;
3233 GBitmap * dictation_icon ;
3334 GBitmap * more_icon ;
3435 TextLayer * time_layer ;
@@ -37,6 +38,7 @@ struct RootWindow {
3738 EventHandle event_handle ;
3839 char time_string [6 ];
3940 char version_string [9 ];
41+ char * * sample_prompts ;
4042};
4143
4244static void prv_window_load (Window * window );
@@ -47,6 +49,9 @@ static void prv_prompt_clicked(ClickRecognizerRef recognizer, void *context);
4749static void prv_more_clicked (ClickRecognizerRef recognizer , void * context );
4850static void prv_up_clicked (ClickRecognizerRef recognizer , void * context );
4951static void prv_time_changed (struct tm * tick_time , TimeUnits time_changed , void * context );
52+ static int prv_load_suggestions (char * * * suggestions );
53+ static void prv_action_menu_closed (ActionMenu * action_menu , const ActionMenuItem * performed_action , void * context );
54+ static void prv_suggestion_clicked (ActionMenu * action_menu , const ActionMenuItem * action , void * context );
5055
5156RootWindow * root_window_create () {
5257 RootWindow * window = malloc (sizeof (RootWindow ));
@@ -58,10 +63,12 @@ RootWindow* root_window_create() {
5863 });
5964 GRect bounds = layer_get_bounds (window_get_root_layer (window -> window ));
6065 window_set_background_color (window -> window , COLOR_FALLBACK (ACCENT_COLOUR , GColorWhite ));
66+ window -> question_icon = gbitmap_create_with_resource (RESOURCE_ID_QUESTION_ICON );
6167 window -> dictation_icon = gbitmap_create_with_resource (RESOURCE_ID_DICTATION_ICON );
6268 window -> more_icon = gbitmap_create_with_resource (RESOURCE_ID_MORE_ICON );
6369 window -> action_bar = action_bar_layer_create ();
6470 action_bar_layer_set_context (window -> action_bar , window );
71+ action_bar_layer_set_icon (window -> action_bar , BUTTON_ID_UP , window -> question_icon );
6572 action_bar_layer_set_icon (window -> action_bar , BUTTON_ID_SELECT , window -> dictation_icon );
6673 action_bar_layer_set_icon (window -> action_bar , BUTTON_ID_DOWN , window -> more_icon );
6774 window_set_user_data (window -> window , window );
@@ -95,6 +102,7 @@ void root_window_push(RootWindow* window) {
95102void root_window_destroy (RootWindow * window ) {
96103 window_destroy (window -> window );
97104 action_bar_layer_destroy (window -> action_bar );
105+ gbitmap_destroy (window -> question_icon );
98106 gbitmap_destroy (window -> dictation_icon );
99107 gbitmap_destroy (window -> more_icon );
100108 text_layer_destroy (window -> time_layer );
@@ -154,13 +162,68 @@ static void prv_click_config_provider(void *context) {
154162
155163static void prv_up_clicked (ClickRecognizerRef recognizer , void * context ) {
156164 RootWindow * rw = context ;
157- talking_horse_layer_set_text (rw -> talking_horse_layer , "I'm doing thanks! How help?" );
165+ // talking_horse_layer_set_text(rw->talking_horse_layer, "I'm doing thanks! How help?");
166+ char * * suggestions ;
167+ int count = prv_load_suggestions (& suggestions );
168+ ActionMenuLevel * level = action_menu_level_create (count );
169+ for (int i = 0 ; i < count ; ++ i ) {
170+ action_menu_level_add_action (level , suggestions [i ], prv_suggestion_clicked , rw );
171+ }
172+ ActionMenuConfig config = (ActionMenuConfig ) {
173+ .root_level = level ,
174+ .colors = {
175+ .background = BRANDED_BACKGROUND_COLOUR ,
176+ .foreground = gcolor_legible_over (BRANDED_BACKGROUND_COLOUR ),
177+ },
178+ .align = ActionMenuAlignTop ,
179+ .context = rw ,
180+ .did_close = prv_action_menu_closed ,
181+ };
182+ rw -> sample_prompts = suggestions ;
183+ action_menu_open (& config );
184+ }
185+
186+ static void prv_action_menu_closed (ActionMenu * action_menu , const ActionMenuItem * performed_action , void * context ) {
187+ RootWindow * rw = context ;
188+ action_menu_hierarchy_destroy (action_menu_get_root_level (action_menu ), NULL , NULL );
189+ // memory is allocated for sample_prompts[0], but not the rest of the entries - so just free the first one.
190+ free (rw -> sample_prompts [0 ]);
191+ free (rw -> sample_prompts );
192+ }
193+
194+ static void prv_suggestion_clicked (ActionMenu * action_menu , const ActionMenuItem * action , void * context ) {
195+ RootWindow * rw = context ;
196+ char * suggestion = action_menu_item_get_label (action );
197+ session_window_push (0 , suggestion );
158198}
159199
160200static void prv_prompt_clicked (ClickRecognizerRef recognizer , void * context ) {
161- session_window_push (0 );
201+ session_window_push (0 , NULL );
162202}
163203
164204static void prv_more_clicked (ClickRecognizerRef recognizer , void * context ) {
165205 root_menu_window_push ();
166206}
207+
208+ static int prv_load_suggestions (char * * * suggestions ) {
209+ ResHandle handle = resource_get_handle (RESOURCE_ID_SAMPLE_PROMPTS );
210+ size_t size = resource_size (handle );
211+ char * buffer = malloc (size );
212+ resource_load (handle , (uint8_t * )buffer , size );
213+ int count = 1 ;
214+ for (size_t i = 0 ; i < size ; ++ i ) {
215+ if (buffer [i ] == '\n' ) {
216+ ++ count ;
217+ }
218+ }
219+ * suggestions = malloc (sizeof (char * ) * count );
220+ for (int i = 0 ; i < count ; ++ i ) {
221+ (* suggestions )[i ] = buffer ;
222+ buffer = strchr (buffer , '\n' );
223+ if (buffer ) {
224+ * buffer = '\0' ;
225+ ++ buffer ;
226+ }
227+ }
228+ return count ;
229+ }
0 commit comments