Mobile native

Managing Menu and Back Key Events

The Menu and Back functions are common UX behaviors in applications. Generally, the user taps the Back hardware key to return to the previous screen. The applications usually also provide option menus to manipulate their functions through the tapping of the Menu hardware key.

This feature is supported in mobile applications only.

Normally, the key events are only delivered to the object in focus. However, with the EFL Extension functions, you can let visible objects without focus get events from the Menu and Back keys.

Figure: Menu and Back keys

Menu and Back keys

The EFL Extension maintains its own object stack for determining which object to deliver events to. Only visible objects are added to this stack. The stack is based on the Evas layer. It means that if 2 objects are registered for the same EFL Extension event, the object on the higher Evas layer gets the event.

The following figure shows an example of objects and their layers. Objects 1, 2, and 3 are registered with EFL Extension callbacks for the same event, such as a Back key event. When the event occurs, object 3, which is on the highest layer (layer 3), gets the event callback.

Figure: Objects with layers

Objects with layers

If objects stay on the same layer, the object which is registered to the callback first gets the event.

To register a callback for the Menu or Back key, use the eext_object_event_callback_add() function with the application callback type:

  • EEXT_CALLBACK_BACK: Hardware Back key event
  • EEXT_CALLBACK_MORE: Hardware Menu key event

To delete a registered event in the EFL Extension, use the eext_object_event_callback_del() function.

The EFL Extension also provides other convenient functions to work with the Menu and Back keys for popup, ctxpopup, naviframe, and entry components.

Managing Hardware Key Events

The application has a window that contains a naviframe and registers the EFL Extension Menu and Back key events for the naviframe.

When the Menu key is pressed, a popup is created and an EFL Extension Back key event for this popup is registered. If the popup is shown and the Back key is pressed, the popup is removed. Otherwise, if the Back key is pressed and there is no popup, the application is hidden.

To manage hardware key events:

  1. To use the functions and data types of the Efl Extension API, include the <efl_extension.h> header file in your application:

    #include <efl_extension.h>
    
  2. Create objects using the window and naviframe:
    static void
    create_base_gui(appdata_s *ad)
    {
       Evas_Object *win = NULL;
    
       // Create the window
       win = elm_win_util_standard_add(NULL, "extension sample");
       evas_object_smart_callback_add(win, "delete,request", _win_del, NULL);
    
       // Create the naviframe
       Evas_Object *nf = NULL;
       nf = elm_naviframe_add(win);
       evas_object_size_hint_weight_set(win, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
       elm_win_resize_object_add(win, nf);
       evas_object_show(nf);
    
       // Content
       Evas_Object *label = NULL;
       label = elm_label_add(nf);
       elm_object_text_set(label, "Press menu key to show popup,<br/>back key to exit.");
       elm_naviframe_item_push(nf, "Efl Extension usage", NULL, NULL, label, NULL);
    
       // Show the window
       evas_object_show(win);
    }
    
  3. Register EFL Extension callbacks for the naviframe:
    static void
    create_base_gui(appdata_s *ad)
    {
       // Register the EFL extension callbacks for Menu and Back key events
       eext_object_event_callback_add(nf, EEXT_CALLBACK_MORE, _create_popup, NULL);
       eext_object_event_callback_add(nf, EEXT_CALLBACK_BACK, _nf_back_cb, win);
    }
    
  4. Create a popup and register EFL Extension Back key event callbacks for it:
    static void
    _create_popup(void *data, Evas_Object *obj, void *event_info)
    {
       Evas_Object *parent = obj;
    
       Evas_Object *popup = NULL, *content = NULL;
       popup = elm_popup_add(parent);
       elm_object_part_text_set(popup, "title,text", "Title");
       elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
    
       // Popup content
       content = elm_label_add(parent);
       elm_object_text_set(content, "Press back key to remove popup.");
       elm_object_content_set(popup, content);
    
       // Register the EFL extension callback for the Back key event
       eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, eext_popup_back_cb, NULL);
       evas_object_show(popup);
    }
    

    To remove the popup when a Back key event occurs, use the eext_popup_back_cb callback.

    The callback function for menu key callback:

    static void
    _nf_back_cb(void *data, Evas_Object *obj, void *event_info)
    {
       Evas_Object *win = data;
    
       // Hide the window
       elm_win_lower(win);
    }
    
Go to top