Skip to content

Instantly share code, notes, and snippets.

@exiva
Created September 18, 2015 05:40
Show Gist options
  • Save exiva/fc02e9d930f147d9cf7f to your computer and use it in GitHub Desktop.
Save exiva/fc02e9d930f147d9cf7f to your computer and use it in GitHub Desktop.
static Layer *popup_dialog;
static TextLayer *s_dialog_message;
static PropertyAnimation *dialog_in_animation;
static void drawFrame(Layer *layer, GContext *ctx) {
graphics_context_set_stroke_color(ctx, GColorBlack);
graphics_context_set_fill_color(ctx, GColorWhite);
graphics_draw_rect(ctx, GRect(6,15,129,72));
graphics_fill_rect(ctx, GRect(7,16,127,70),0,GCornerNone);
}
static void popup_in_animation_end() {
animation_unschedule((Animation*)dialog_in_animation);
property_animation_destroy(dialog_in_animation);
dialog_in_animation = NULL;
//Free heap after: 4376
}
static void popup_in_animation() {
dialog_in_animation = property_animation_create_layer_frame(popup_dialog, NULL, &GRect(0, 49, 144, 89));
animation_set_duration((Animation*)dialog_in_animation, 1000);
animation_set_delay((Animation*)dialog_in_animation, 1000);
animation_set_handlers((Animation*) dialog_in_animation, (AnimationHandlers) {
.stopped = (AnimationStoppedHandler) popup_in_animation_end,
}, NULL);
animation_schedule((Animation*)dialog_in_animation);
}
void show_popup(Window *window, char *message) {
popup_dialog = layer_create(GRect(144,49,144,89));
layer_add_child(window_get_root_layer(window),popup_dialog);
layer_set_update_proc(popup_dialog, drawFrame);
s_dialog_message = text_layer_create(GRect(8, 41, 125, 44));
text_layer_set_text(s_dialog_message, message);
text_layer_set_font(s_dialog_message, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
text_layer_set_text_alignment(s_dialog_message, GTextAlignmentCenter);
text_layer_set_background_color(s_dialog_message, GColorClear);
text_layer_set_text_color(s_dialog_message, GColorBlack);
layer_add_child(popup_dialog, text_layer_get_layer(s_dialog_message));
popup_in_animation();
//Free heap: 6884
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment