Ejemplo n.º 1
0
static void onWindowLoad(Window *window) {
    // 配置按键
    window_set_click_config_provider(window, clickConfigProvider);

    // 窗口信息
    Layer *layer = window_get_root_layer(window);
    bounds = layer_get_bounds(layer);

    // bitmap图层
    GRect fromRect = GRect(0, 0, bounds.size.w, bounds.size.h);
    GRect toRect = GRect(0, bounds.size.h, bounds.size.w, bounds.size.h);
    bitmapLayer = bitmap_layer_create(fromRect);

    // bitmap对象
    bitmap = gbitmap_create_with_resource(RESOURCE_ID_MY_LOGO);
    bitmap_layer_set_compositing_mode(bitmapLayer, GCompOpSet);
    bitmap_layer_set_bitmap(bitmapLayer, bitmap);

    // logo动画
    PropertyAnimation *propAnim = property_animation_create_layer_frame((Layer *)bitmapLayer, &fromRect, &toRect);
    Animation *anim = property_animation_get_animation(propAnim);
    const int delay_ms = 1000;
    const int duration_ms = 3000;
    animation_set_curve(anim, AnimationCurveEaseOut);
    animation_set_delay(anim, delay_ms);
    animation_set_duration(anim, duration_ms);
    animation_schedule(anim);

    // 添加图层
    layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(bitmapLayer));
}
Ejemplo n.º 2
0
// Animate device cards to make it look like they are being scrolled
// up or down when switching devices
static void animate_cards(GRect *from, GRect *to) {
  
  s_pa_old = property_animation_create_layer_frame(s_devicecard_layer_old->layer, &s_rect_onscreen, to);
  s_pa_new = property_animation_create_layer_frame(s_devicecard_layer->layer, from, &s_rect_onscreen);
  
  animation_set_handlers(IF_32(property_animation_get_animation(s_pa_old), &(s_pa_old->animation)), 
                         (AnimationHandlers) {
    .stopped = devicecard_anim_old_stopped
  }, NULL);
static void shake_animation() {
  Layer *text_layer = text_layer_get_layer(s_text_layer);
  GRect start = layer_get_frame(text_layer);
  GRect finish = GRect(start.origin.x - TEXT_ANIMATION_WINDOW_DISTANCE, start.origin.y, start.size.w, start.size.h);

  PropertyAnimation *out_prop_anim = property_animation_create_layer_frame(text_layer, &start, &finish);
  Animation *out_anim = property_animation_get_animation(out_prop_anim);
  animation_set_curve(out_anim, AnimationCurveEaseInOut);
  animation_set_duration(out_anim, TEXT_ANIMATION_WINDOW_DURATION);
  animation_set_handlers(out_anim, (AnimationHandlers) {
    .stopped = out_stopped_handler
  }, NULL);
static void out_stopped_handler(Animation *animation, bool finished, void *context) {
  s_current_text += (s_current_text == 0) ? 1 : -1;
  text_layer_set_text(s_text_layer, s_text[s_current_text]);

  Layer *text_layer = text_layer_get_layer(s_text_layer);
  GRect frame = layer_get_frame(text_layer);
  GRect start = GRect(frame.origin.x + (2 * TEXT_ANIMATION_WINDOW_DISTANCE), frame.origin.y, frame.size.w, frame.size.h);
  GRect finish = GRect(frame.origin.x + TEXT_ANIMATION_WINDOW_DISTANCE, frame.origin.y, frame.size.w, frame.size.h);

  PropertyAnimation *in_prop_anim = property_animation_create_layer_frame(text_layer, &start, &finish);
  Animation *in_anim = property_animation_get_animation(in_prop_anim);
  animation_set_curve(in_anim, AnimationCurveEaseInOut);
  animation_set_duration(in_anim, TEXT_ANIMATION_WINDOW_DURATION);
  animation_schedule(in_anim);
}
Ejemplo n.º 5
0
static Animation* prv_create_slide_settle_animation(Layer *layer) {
  SelectionLayerData *data = layer_get_data(layer);
  PropertyAnimation *slide_settle_anim = property_animation_create_layer_frame(layer, NULL, NULL);
  Animation *animation = property_animation_get_animation(slide_settle_anim);
  animation_set_curve(animation, AnimationCurveEaseOut);
  animation_set_duration(animation, SLIDE_SETTLE_DURATION_MS);
  AnimationHandlers anim_handler = {
      .stopped = prv_slide_settle_stopped,
  };
  animation_set_handlers(animation, anim_handler, layer);

  data->slide_settle_anim_impl = (AnimationImplementation) {
    .update = prv_slide_settle_impl,
  };
  animation_set_implementation(animation, &data->slide_settle_anim_impl);

  return animation;
}
Ejemplo n.º 6
0
static Animation* prv_create_bump_text_animation(Layer *layer) {
  SelectionLayerData *data = layer_get_data(layer);
  
  PropertyAnimation *bump_text_anim = property_animation_create_layer_frame(layer, NULL, NULL);
  Animation *animation = property_animation_get_animation(bump_text_anim);
  animation_set_curve(animation, AnimationCurveEaseIn);
  animation_set_duration(animation, BUMP_TEXT_DURATION_MS);
  AnimationHandlers anim_handler = {
      .stopped = prv_bump_text_stopped,
  };
  animation_set_handlers(animation, anim_handler, layer);

  data->bump_text_impl = (AnimationImplementation) {
    .update = prv_bump_text_impl,
  };
  animation_set_implementation(animation, &data->bump_text_impl);

  return animation;
}
Ejemplo n.º 7
0
  devicecard_layer_set_status_changed(s_devicecard_layer, "");
  
}

// Animate device cards to make it look like they are being scrolled
// up or down when switching devices
static void animate_cards(GRect *from, GRect *to) {
  
  s_pa_old = property_animation_create_layer_frame(s_devicecard_layer_old->layer, &s_rect_onscreen, to);
  s_pa_new = property_animation_create_layer_frame(s_devicecard_layer->layer, from, &s_rect_onscreen);
  
  animation_set_handlers(IF_32(property_animation_get_animation(s_pa_old), &(s_pa_old->animation)), 
                         (AnimationHandlers) {
    .stopped = devicecard_anim_old_stopped
  }, NULL);
  animation_set_handlers(IF_32(property_animation_get_animation(s_pa_new), &(s_pa_new->animation)), 
                         (AnimationHandlers) {
    .stopped = devicecard_anim_new_stopped
  }, NULL);
  
  animation_schedule((Animation*)s_pa_old);
  animation_schedule((Animation*)s_pa_new); 
  
}

static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
  // Select button triggers device status change
  if (s_statuschange_callback != NULL) s_statuschange_callback();
}

static void up_click_handler(ClickRecognizerRef recognizer, void *context) {