Wearable native

Widget Animation Sample Overview

The Widget Animation sample demonstrates how you can use an animation in your widget application to show a simple image rotation.

The following figure illustrates the main view of the Widget Animation application.

Figure: Widget Animation main view

Widget Animation main view

Implementation

To implement the Widget Animation application:

  1. Create a widget application by calling the widget_app_main() function in the main function. You can register the widget application life-cycle callbacks when you call the widget_app_main() function.
    widget_app_lifecycle_callback_s ops = { 0, };
    int ret;
    
    ops.create = widget_app_create;
    ops.terminate = widget_app_terminate;
    
    ret = widget_app_main(argc, argv, &ops, NULL);
    if (ret != WIDGET_ERROR_NONE) 
    {
       dlog_print(DLOG_ERROR, LOG_TAG, "widget_app_main() is failed. err = %d", ret);
    }
    
  2. Create the widget application instance with the widget_app_class_create() function. It adds the widget instance life-cycle callbacks.
    static widget_class_h
    widget_app_create(void *user_data) 
    {	
       widget_instance_lifecycle_callback_s ops = 
       { 
          .create = widget_instance_create, 
          .destroy = widget_instance_destroy, 
          .pause = widget_instance_pause, 
          .resume = widget_instance_resume, 
          .update = widget_instance_update, 
          .resize = widget_instance_resize, 
       };
    
       return widget_app_class_create(ops, user_data);
    }
    
  3. Get the widget application instance's window with the widget_app_get_elm_win() function and draw the animation effect:
    widget_instance_data_s *wid = (widget_instance_data_s*) malloc(sizeof(widget_instance_data_s));
    int ret;
    // Window
    ret = widget_app_get_elm_win(context, &wid->win);
    if (ret != WIDGET_ERROR_NONE) 
    {
       dlog_print(DLOG_ERROR, LOG_TAG, "failed to get window. err = %d", ret);
    
       return WIDGET_ERROR_FAULT;
    }
    evas_object_resize(wid->win, w, h);
    
  4. Add an image to the widget application window:
    // Animation
    wid->ship = evas_object_image_filled_add(evas_object_evas_get(wid->win));
    
    char buf[256];
    
    snprintf(buf, sizeof(buf), "%s/ship.png", app_get_resource_path());
    evas_object_image_file_set(wid->ship, buf, NULL);
    evas_object_resize(wid->ship, SHIP_IMAGE_WIDTH, SHIP_IMAGE_HEIGHT);
    evas_object_move(wid->ship, 100, 150);
    evas_object_show(wid->ship);
    
  5. Add the animation effect with the ecore_animator_timeline_add() function:
    Ecore_Animator *animator = ecore_animator_timeline_add(ANIM_TIME, _do_animation, wid->ship);
    
Go to top