Languages

Menu
Sites
Language
When is the orientation changed event callback called?

In my native Tizen 2.3 mobile app I'd like to show a popup menu when the user presses the menu button, and adjust the placement of the popup menu in case the user rotates the device while the menu is open. However, by registering a callback for APP_EVENT_DEVICE_ORIENTATION_CHANGED, it looks to me as if the callback procedure is only called _before_ the orientation change on the UI takes place. And it makes it impossible for me to measure the current window dimensions and move the menu to the right place on the device screen. I've tried to use debugging to see if it works the way I assume, and it seems it does. So when the callback procedure is fired, the device is already physically rotated, but the UI is not yet rotated. I would like to have a callback procedure called _after_ the UI is adjusted for the new orientation state, but I'm not sure if it's possible with Tizen?

My code looks like this:

int main(int argc, char *argv[])
{
...

  ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, &ad);
...

}

 

static void ui_app_orient_changed(app_event_info_h event_info, void *user_data)
{
 appdata_s *ad = user_data;
 if (ad->popup) move_menu_popup(ad->win, ad->popup);
}
 

static void move_menu_popup(Evas_Object *parent, Evas_Object *obj)
{
 Evas_Coord w, h;
 int pos = -1;

 elm_win_screen_size_get(parent, NULL, NULL, &w, &h);
 pos = elm_win_rotation_get(parent);

 switch (pos) {
  case 0:
  case 180:
   evas_object_move(obj, 0, h);
   break;
  case 90:
   evas_object_move(obj, 0, w);
   break;
  case 270:
   evas_object_move(obj, h, w);
   break;
 }
}

 

Thank you.

Regards,
Tamas

Edited by: Tamas Miklos on 15 Jun, 2015

Responses

3 Replies
Jeongsu Kim

I think you can get orientation by this api in the callback function.

int  app_event_get_device_orientation (app_event_info_h event_info, app_device_orientation_e *orientation)
  Gets the device orientation from given event info.
Tamas Miklos

Thank you for your reply. The problem is that when I call [b]app_event_get_device_orientation[/b] and [b]elm_win_rotation_get[/b] from my callback function, they report mismatching information. [b]app_event_get_device_orientation[/b] already reports the new orientation state, while [b]elm_win_rotation_get[/b] reports the old state. [b]elm_win_screen_size_get[/b] also reports the window dimensions corresponding to the old orientation state. Is this normal? If yes, then is it possible to somehow initiate the windows state to be updated, to make sure both [b]elm_win_rotation_get[/b] and [b]elm_win_screen_size_get[/b] report the right values for the new orientation state?  If it's not possible, then I have to implement a workaround to override the values reported by [b]elm_win_screen_size_get[/b], but I'm hesitant to do such tweakings because in future updates to the Tizen API such workarounds may cause other issues...

Alex Dem

Hi,
As I guess you have added standard code snippet to support rotation with Window manager, but per my it opinion should not be syncronized with ui_app_orient_changed call.
I think you could use 2 ways to rotation support:
1) Just add under:

if (elm_win_wm_rotation_supported_get(ad->win))
{
    int rots[4] = { 0, 90, 180, 270 };
    elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
}
evas_object_smart_callback_add(ad->win, "wm,rotation,changed", rotation_cb, ad);

and perform necessary actions inside rotation_cb

static void
rotation_cb(void *data, Evas_Object *obj, void *event_info)
{
    appdata_s * ad= data;
    LOGI("rotation_cb %d",elm_win_rotation_get(ad->win));
//... some code
}

2) remove standard rotation support with elm_win_wm_rotation_available_rotations_set and implement rotation inside ui_app_orient_changed this way:
 

static void
ui_app_orient_changed(app_event_info_h event_info, void *user_data)
{
    appdata_s * ad= user_data;
    app_device_orientation_e  orientation ;
    app_event_get_device_orientation (event_info,&orientation);
    elm_win_rotation_with_resize_set(ad->win,orientation);
    LOGI("ui_app_orient_changed %d",orientation);
    LOGI("ui_app_orient_changed %d",elm_win_rotation_get(ad->win));
//... some code
    return;
}

Both approaches should work.

Try to look here also:
https://developer.tizen.org/documentation/articles/responsive-ui-tizen-native
Alexey.