コード例 #1
0
ファイル: time_window.c プロジェクト: xabbudm/time-tracker
TimeWindow* time_window_create(TimeWindowCallbacks callbacks, ETimeState state) {
    TimeWindow *time_window = (TimeWindow*)malloc(sizeof(TimeWindow));
    if (time_window) {
        time_window->window = window_create();
        time_window->callbacks = callbacks;
        if (time_window->window) 
        {
            time_t current_time = time(NULL);
            struct tm* current_tm = localtime(&current_time);
            
            time_window->field_selection = 0;
            time_window->state = state;
            time_window->time.digits[0] = current_tm->tm_hour;
            time_window->time.digits[1] = current_tm->tm_min;
//            for(int i = 0; i < TIME_WINDOW_NUM_CELLS; i++) {
//                time_window->time.digits[i] = 0;
//            }

            // Get window parameters
            Layer *window_layer = window_get_root_layer(time_window->window);
            GRect bounds = layer_get_bounds(window_layer);

            // Main TextLayer
            const GEdgeInsets main_text_insets = {.top = 30};
            time_window->main_text = text_layer_create(grect_inset(bounds, main_text_insets));
            text_layer_set_text(time_window->main_text, "Time Required");
            text_layer_set_font(time_window->main_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
            text_layer_set_text_alignment(time_window->main_text, GTextAlignmentCenter);
            layer_add_child(window_layer, text_layer_get_layer(time_window->main_text));

            // Sub TextLayer
            const GEdgeInsets sub_text_insets = {.top = 115, .right = 5, .bottom = 10, .left = 5};
            time_window->sub_text = text_layer_create(grect_inset(bounds, sub_text_insets));
            text_layer_set_text(time_window->sub_text, "up/down to change time");
            text_layer_set_text_alignment(time_window->sub_text, GTextAlignmentCenter);
            text_layer_set_font(time_window->sub_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
            layer_add_child(window_layer, text_layer_get_layer(time_window->sub_text));

            // Create selection layer
            const GEdgeInsets selection_insets = GEdgeInsets(
                (bounds.size.h - TIME_WINDOW_SIZE.h) / 2,
                (bounds.size.w - TIME_WINDOW_SIZE.w) / 2);
            time_window->selection = selection_layer_create(grect_inset(bounds, selection_insets), TIME_WINDOW_NUM_CELLS);
            for (int i = 0; i < TIME_WINDOW_NUM_CELLS; i++) {
                selection_layer_set_cell_width(time_window->selection, i, 60);
            }
            selection_layer_set_cell_padding(time_window->selection, 6);
            selection_layer_set_active_bg_color(time_window->selection, GColorRed);
            selection_layer_set_inactive_bg_color(time_window->selection, GColorDarkGray);
            selection_layer_set_click_config_onto_window(time_window->selection, time_window->window);
            selection_layer_set_callbacks(time_window->selection, time_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(time_window->window), time_window->selection);

            // Create status bar
            time_window->status = status_bar_layer_create();
            status_bar_layer_set_colors(time_window->status, GColorClear, GColorBlack);
            layer_add_child(window_layer, status_bar_layer_get_layer(time_window->status));
            return time_window;
        }
    }

  APP_LOG(APP_LOG_LEVEL_ERROR, "Failed to create TimeWindow");
  return NULL;
}
コード例 #2
0
ファイル: pin_window.c プロジェクト: epageron/PebbleApps
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);
}
コード例 #3
0
PinWindow* pin_window_create(PinWindowCallbacks callbacks) {
  PinWindow *pin_window = (PinWindow*)malloc(sizeof(PinWindow));
  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 < NUM_CELLS; i++) {
        pin_window->pin.digits[i] = 0;
      }
      
      // Get window parameters
      Layer *window_layer = window_get_root_layer(pin_window->window);
      GRect bounds = layer_get_bounds(window_layer);
      
      // Main TextLayer
#ifdef PBL_SDK_3
      pin_window->main_text = text_layer_create(GRect(0, 30, bounds.size.w, 40));
#else
      pin_window->main_text = text_layer_create(GRect(0, 15, bounds.size.w, 40));
#endif
      text_layer_set_text(pin_window->main_text, "How many?");
      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));
      
      // Sub TextLayer
#ifdef PBL_SDK_3
      pin_window->sub_text = text_layer_create(GRect(1, 125, bounds.size.w, 40));
#else
      pin_window->sub_text = text_layer_create(GRect(1, 110, bounds.size.w, 40));
#endif

      // Create selection layer
#ifdef PBL_SDK_3
      pin_window->selection = selection_layer_create(GRect(8, 75, 128, 34), NUM_CELLS);
#else
      pin_window->selection = selection_layer_create(GRect(8, 60, 128, 34), NUM_CELLS);
#endif
      for (int i = 0; i < NUM_CELLS; i++) {
        selection_layer_set_cell_width(pin_window->selection, i, 40);
      }
      selection_layer_set_cell_padding(pin_window->selection, 4);
#ifdef PBL_COLOR
      selection_layer_set_active_bg_color(pin_window->selection, GColorRed);
      selection_layer_set_inactive_bg_color(pin_window->selection, GColorDarkGray);
#endif
      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);

#ifdef PBL_SDK_3

#endif
      return pin_window;
    }