Exemplo n.º 1
0
void time_window_destroy(TimeWindow *time_window) {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "destroy time window");
  if (time_window) {
    status_bar_layer_destroy(time_window->status);
    selection_layer_destroy(time_window->selection);
    text_layer_destroy(time_window->sub_text);
    text_layer_destroy(time_window->main_text);
    free(time_window);
    time_window = NULL;
    return;
  }
}
Exemplo n.º 2
0
PinWindow* pin_window_create(PinWindowCallbacks callbacks, PinWindowData data) {
  PinWindow *pin_window = (PinWindow*)malloc(sizeof(PinWindow));
  if (data.nb_digits==0)
    data.nb_digits = PIN_WINDOW_NUM_CELLS;
  if (pin_window) {
    pin_window->window = window_create();
    pin_window->callbacks = callbacks;
    if (pin_window->window) {
      pin_window->field_selection = 0;
      for(int i = 0; i < data.nb_digits; i++) {
        pin_window->pin.digits[i] = data.init_pin->digits[i];
      }
      
      // Get window parameters
      Layer *window_layer = window_get_root_layer(pin_window->window);
      GRect bounds = layer_get_bounds(window_layer);
      // Main TextLayer
      const GEdgeInsets main_text_insets = {.top = 30};
      pin_window->main_text = text_layer_create(grect_inset(bounds, main_text_insets));
      text_layer_set_text(pin_window->main_text, data.main_text);
      text_layer_set_font(pin_window->main_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
      text_layer_set_text_alignment(pin_window->main_text, GTextAlignmentCenter);
      layer_add_child(window_layer, text_layer_get_layer(pin_window->main_text));
      // Separators layer
      const GEdgeInsets sep_text_insets = {.top = 75};
      pin_window->sep_text = text_layer_create(grect_inset(bounds, sep_text_insets));
      if(data.nb_digits==3)
        text_layer_set_text(pin_window->sep_text, "        :          :      ");
      else
        text_layer_set_text(pin_window->sep_text, "      :     ");
      text_layer_set_font(pin_window->sep_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
      text_layer_set_text_alignment(pin_window->sep_text, GTextAlignmentCenter);
      layer_add_child(window_layer, text_layer_get_layer(pin_window->sep_text));
      // Sub TextLayer
      const GEdgeInsets sub_text_insets = {.top = 115, .right = 5, .bottom = 10, .left = 5};
      pin_window->sub_text = text_layer_create(grect_inset(bounds, sub_text_insets));
      text_layer_set_text(pin_window->sub_text, data.sub_text);
      text_layer_set_text_alignment(pin_window->sub_text, GTextAlignmentCenter);
      text_layer_set_font(pin_window->sub_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
      layer_add_child(window_layer, text_layer_get_layer(pin_window->sub_text));
      // Create selection layer
      const GEdgeInsets selection_insets = GEdgeInsets(
        (bounds.size.h - PIN_WINDOW_SIZE.h) / 2,
        (bounds.size.w - (40 * data.nb_digits)) / 2);
      pin_window->selection = selection_layer_create(grect_inset(bounds, selection_insets), data.nb_digits);
      for (int i = 0; i < data.nb_digits; i++) {
        selection_layer_set_cell_width(pin_window->selection, i, 40);
      }
      selection_layer_set_cell_padding(pin_window->selection, 4);
      selection_layer_set_active_bg_color(pin_window->selection, GColorRed);
      selection_layer_set_inactive_bg_color(pin_window->selection, GColorDarkGray);
      selection_layer_set_click_config_onto_window(pin_window->selection, pin_window->window);
      selection_layer_set_callbacks(pin_window->selection, pin_window, (SelectionLayerCallbacks) {
        .get_cell_text = selection_handle_get_text,
        .complete = selection_handle_complete,
        .increment = selection_handle_inc,
        .decrement = selection_handle_dec,
        });
      layer_add_child(window_get_root_layer(pin_window->window), pin_window->selection);
      // Create status bar
      pin_window->status = status_bar_layer_create();
      status_bar_layer_set_colors(pin_window->status, GColorClear, GColorBlack);
      layer_add_child(window_layer, status_bar_layer_get_layer(pin_window->status));
      return pin_window;
    }
  }
  APP_LOG(APP_LOG_LEVEL_ERROR, "Failed to create PinWindow");
  return NULL;
}

void pin_window_destroy(PinWindow *pin_window) {
  if (pin_window) {
    status_bar_layer_destroy(pin_window->status);
    selection_layer_destroy(pin_window->selection);
    text_layer_destroy(pin_window->sub_text);
    text_layer_destroy(pin_window->main_text);
    text_layer_destroy(pin_window->sep_text);
    free(pin_window);
    pin_window = NULL;
    return;
  }
}

void pin_window_push(PinWindow *pin_window, bool animated) {
  window_stack_push(pin_window->window, animated);
}