apply rotate routine
authorJisung Ahn <jcastle.ahn@samsung.com>
Thu, 11 Apr 2013 09:37:25 +0000 (18:37 +0900)
committerJisung Ahn <jcastle.ahn@samsung.com>
Thu, 11 Apr 2013 10:51:14 +0000 (19:51 +0900)
Change-Id: I6adc6e8ef7b9d6db4c0fd522ad180ade2a3e5c4f

CMakeLists.txt
include/image-viewer.h [changed mode: 0644->0755]
src/image-viewer.c

index 7b5098b..762c38b 100755 (executable)
@@ -20,7 +20,6 @@ pkg_check_modules(pkgs REQUIRED
        ecore-x
        ecore
        ecore-input
-       vconf
        capi-appfw-application
        dlog
 )
old mode 100644 (file)
new mode 100755 (executable)
index 36b3a0f..d80ffb9
@@ -52,8 +52,6 @@
                 } \
         } while (0)
 
-#define USE_CONFORMANT
-
 /*
 
        win_main : elm_win
@@ -69,10 +67,9 @@ typedef struct {
 
        Evas_Object *win_main;
 
-#ifdef USE_CONFORMANT
        Evas_Object *conformant;
-       bool bUseConforment;
-#endif
+
+       Evas_Object *black_obj;
 
        Evas_Object *lyBase;
 
index 58651c9..a007790 100755 (executable)
@@ -27,9 +27,6 @@
 #include <ui-gadget-module.h>
 #include <ui-gadget.h>
 
-#include <vconf.h>
-#include <vconf-keys.h>
-
 #include "image-viewer.h"
 
 #define PACKAGE "image-viewer"
@@ -142,7 +139,59 @@ static Eina_Bool _exit_timer_cb(void *data)
 
        return ECORE_CALLBACK_CANCEL;
 }
-static void _orient_changed(app_device_orientation_e orientation, void *user_data);
+
+static void
+_rot_changed_cb(void *data, Evas_Object *obj, void *event)
+{
+       appdata_iv *ap = (appdata_iv *)data;
+
+       int changed_ang;
+
+       changed_ang = elm_win_rotation_get(obj);
+
+       IV_MSG_HIGH("Rotation is changed. %d", changed_ang);
+#if 0
+       if (changed_ang != current_ang)
+       {
+       current_ang = changed_ang;
+       // Perform an UI update according to the given rotation angle.
+       // Do not call elm_win_rotation_set / elm_win_rotation_with_resize_set.
+       // ecore_evas has already called elm_win_rotation_set / elm_win_rotation_with_resize_set function.
+       ...
+       }
+#endif
+       int degree = 0;
+       enum ug_event evt = UG_EVENT_NONE;
+
+       switch(changed_ang)
+       {
+               case 0:
+              degree = 0;
+              evt = UG_EVENT_ROTATE_PORTRAIT;
+              break;
+               case 90:
+              degree = 90;
+              evt = UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN;
+              break;
+
+               case 180:
+              degree = 180;
+              evt = UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN;
+              break;
+
+               case 270:
+              evt = UG_EVENT_ROTATE_LANDSCAPE;
+              degree = 270;
+              break;
+               default:
+                       IV_MSG_ERROR("Unknown rotation degree. %d", changed_ang);
+                       return;
+                       break;
+       }
+
+       ug_send_event( evt );
+
+}
 
 
 /**
@@ -176,11 +225,31 @@ static Evas_Object* _create_win(const char *name)
        {
                elm_win_title_set(eo, name);
                evas_object_smart_callback_add(eo, "delete,request", _win_del, NULL);
+               int w, h;
+               ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
+               IV_MSG_HIGH("x_window_size %d, %d", w, h);
+               evas_object_resize (eo, w, h);
        }
 
        return eo;
 }
 
+Evas_Object* _create_bg(Evas_Object* parent, int r, int g, int b)
+{
+    IV_ASSERT(parent != NULL);
+
+       Evas_Object *bg = elm_bg_add(parent);
+       evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
+
+       elm_win_resize_object_add(parent, bg);
+
+       elm_bg_color_set(bg, r,  g, b);
+
+       evas_object_show(bg);
+
+       return bg;
+}
 
 /**
 * @brief The layout callback after ug created
@@ -193,8 +262,6 @@ void _ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void* priv)
 {
        IV_MSG_HIGH("ug Layout CB. UG=0x%08x Priv=0x%08x Mode=%d", ug, priv, mode);
 
-       Evas_Object *win = NULL;
-
        if (!ug || !priv)
        {
                IV_MSG_ERROR("Abnormal value. UG=0x%08x Priv=0x%08x Mode=%d", ug, priv, mode);
@@ -203,6 +270,9 @@ void _ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void* priv)
 
        appdata_iv *ap = (appdata_iv *)priv;
 
+       Evas_Object *win = ap->win_main;
+       IV_ASSERT(win != NULL);
+
        ap->lyClient = ug_get_layout(ug);
 
        if (ap->lyClient == NULL)
@@ -211,25 +281,10 @@ void _ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void* priv)
                return;
        }
 
-       win = ug_get_window();
-       IV_ASSERT(win != NULL);
-
-#ifdef USE_CONFORMANT
        if(ap->lyBase == NULL)
        {
-               if(ap->bUseConforment == true)
-               {
-                       ap->lyBase = elm_layout_add(ap->conformant);
-               }
-               else
-               {
-                       ap->lyBase = elm_layout_add(win);
-               }
-#else
-       if(ap->lyBase == NULL)
-       {
-               ap->lyBase = elm_layout_add(win);
-#endif
+               ap->lyBase = elm_layout_add(ap->conformant);
+
                evas_object_name_set(ap->lyBase, "IV Base");
 
                IV_MSG_HIGH("Load edj : %s", PREFIX"/res/edje/iv-main.edj");
@@ -244,31 +299,16 @@ void _ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void* priv)
        {
                case UG_MODE_FULLVIEW:
                        ug_disable_effect(ug);
-#ifdef USE_CONFORMANT
-                       if(ap->bUseConforment == true)
-                       {
+
                                elm_win_conformant_set(win, EINA_TRUE);
 
                                evas_object_size_hint_weight_set(ap->conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
 
-                               elm_win_resize_object_add(win, ap->conformant);
+                       elm_object_content_set(ap->conformant, ap->lyBase);
 
-                               elm_object_content_set(ap->conformant, ap->lyBase);
+                               elm_win_resize_object_add(win, ap->conformant);
 
                                evas_object_show(ap->conformant);
-                       }
-                       else
-                       {
-                               elm_win_resize_object_add(win, ap->lyBase);
-
-                               evas_object_show(ap->lyBase);
-                       }
-
-#else
-                       elm_win_resize_object_add(win, ap->lyBase);
-
-                       evas_object_show(ap->lyBase);
-#endif
 
 //                     dump_obj(ap->conformant, 0, 10);
                        break;
@@ -276,6 +316,12 @@ void _ug_layout_cb(ui_gadget_h ug, enum ug_mode mode, void* priv)
                        IV_MSG_ERROR("Unknow UG mode : %d", mode);
                        break;
        }
+
+       if(ap->black_obj)
+       {
+               evas_object_del(ap->black_obj);
+               ap->black_obj = NULL;
+       }
 }
 
 /**
@@ -363,38 +409,6 @@ ui_gadget_h _create_ug(void* data)
        return ug;
 }
 
-static bool _is_rotation_lock(void)
-{
-       int lock = 0;
-       int ret = -1;
-
-       ret = vconf_get_bool(VCONFKEY_SETAPPL_AUTO_ROTATE_SCREEN_BOOL, &lock);
-
-       if ( ret != 0)  // Failed
-       {
-               IV_MSG_HIGH( "Rotation locked state is [%d].", lock);
-               return false;
-       }
-
-       if ( lock == 0)
-       {
-               IV_MSG_HIGH("Rotation is locked");
-               return true;
-       }
-
-       return false;
-}
-
-static void _on_portrait_lock_changed(keynode_t* node, void *user_data)
-{
-       IV_MSG_HIGH("State changed. %s=%d", vconf_keynode_get_name(node), vconf_keynode_get_bool(node));
-
-       if ( vconf_keynode_get_bool(node) == true )
-       {
-               // When Set portrait lock, Set degree as 0.
-               _orient_changed(APP_DEVICE_ORIENTATION_0, user_data);
-       }
-}
 
 static bool _iter_extra_data_cb(service_h service, const char *key, void *user_data)
 {
@@ -440,17 +454,17 @@ static bool _app_create(void *user_data)
 
        UG_INIT_EFL(ap->win_main, UG_OPT_INDICATOR_ENABLE);     // Init UG module
 
-       int ret = -1;
-
-       ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ROTATE_LOCK_BOOL, _on_portrait_lock_changed, user_data);
-
-       if ( ret == -1 )
+       if (elm_win_wm_rotation_supported_get(win) == EINA_TRUE)
        {
-               IV_MSG_ERROR("Register %s is failed", VCONFKEY_SETAPPL_ROTATE_LOCK_BOOL);
-               return false;
+               int rots[4] = { 0, 90, 180, 270 };
+               elm_win_wm_rotation_available_rotations_set(win, &rots, 4);
+       }
+       else
+       {
+               IV_MSG_HIGH("Rotation is not supported. ");
        }
 
-       _orient_changed(app_get_device_orientation(), user_data);               // Set initial degree
+       evas_object_smart_callback_add(win, "wm,rotation,changed", _rot_changed_cb, user_data);
 
        //create conformant
        ap->conformant = elm_conformant_add(win);
@@ -505,10 +519,6 @@ static void _app_service(service_h service, void *user_data)
                goto EXIT;
        }
 
-#ifdef USE_CONFORMANT
-       ap->bUseConforment = true;
-#endif
-
        if( strcmp(operation, SERVICE_OPERATION_VIEW) == 0 || strcmp(operation, SERVICE_OPERATION_DEFAULT) == 0)
        {
                if(uri) // uri can entered through argv[1]
@@ -540,7 +550,6 @@ static void _app_service(service_h service, void *user_data)
                                        UTILX_EFFECT_TYPE_MAP, UTILX_EFFECT_STYLE_NONE);
                                utilx_set_window_effect_style((Display*)ecore_x_display_get(), elm_win_xwindow_get(ap->win_main),
                                        UTILX_EFFECT_TYPE_UNMAP, UTILX_EFFECT_STYLE_NONE);
-                               ap->bUseConforment = false;
                        }
                        free(szMode);
                }
@@ -600,6 +609,15 @@ static void _app_service(service_h service, void *user_data)
        {
                // Create Previous UG if exist
                IV_MSG_HIGH("Removing previous UG=0x%08x", ap->iv_ug);
+
+               service_h s = NULL;
+               service_create(&s);
+
+               service_add_extra_data(s, "Destroy", "OK");
+
+               ug_send_message(ap->iv_ug, s);
+               service_destroy(s);
+
                ug_destroy(ap->iv_ug);
                ap->iv_ug = NULL;
        }
@@ -640,6 +658,23 @@ void _app_pause(void *user_data)
 // Take necessary actions when application becomes invisible.
        IV_MSG_HIGH("%s", __func__);
 
+       appdata_iv *ap = (appdata_iv *)user_data;
+
+       if(ap->black_obj == NULL)
+       {
+               ap->black_obj = evas_object_rectangle_add(evas_object_evas_get(ap->conformant));
+               evas_object_color_set(ap->black_obj, 0, 0, 0, 255); /* black bg */
+       }
+
+       ap->lyBase = elm_object_content_unset(ap->conformant);
+
+       ap->lyClient = elm_object_part_content_unset(ap->lyBase, "elm.swallow.content");
+
+       elm_object_part_content_set(ap->lyBase, "elm.swallow.content", ap->black_obj);
+       evas_object_show(ap->black_obj);
+
+       evas_object_hide(ap->lyClient);
+
        ug_pause();
 }
 
@@ -648,6 +683,20 @@ void _app_resume(void *user_data)
 // Take necessary actions when application becomes visible.
        IV_MSG_HIGH("%s", __func__);
 
+       appdata_iv *ap = (appdata_iv *)user_data;
+
+       elm_object_part_content_set(ap->lyBase, "elm.swallow.content", ap->lyClient);
+
+       elm_object_content_set(ap->conformant, ap->lyBase);
+
+       evas_object_show(ap->lyClient);
+
+       if(ap->black_obj)
+       {
+               evas_object_del(ap->black_obj);
+               ap->black_obj = NULL;
+       }
+
        ug_resume();
 }
 
@@ -658,6 +707,12 @@ void _app_terminate(void *user_data)
 
        appdata_iv *ap = (appdata_iv *)user_data;
 
+       if(ap->black_obj)
+       {
+               evas_object_del(ap->black_obj);
+               ap->black_obj = NULL;
+       }
+
        if(ap->service_handle) {
                service_destroy(ap->service_handle);
                ap->service_handle = NULL;
@@ -680,13 +735,12 @@ void _app_terminate(void *user_data)
                evas_object_del(ap->lyBase);
                ap->lyBase = NULL;
        }
-#ifdef USE_CONFORMANT
+
        if(ap->conformant)
        {
                evas_object_del(ap->conformant);
                ap->conformant = NULL;
        }
-#endif
 
        IV_MSG_HIGH("%s terminated.", __func__);
 }
@@ -717,64 +771,6 @@ void _lang_changed(void *user_data)
 
 }
 
-static void _orient_changed(app_device_orientation_e orientation, void *user_data)
-{
-       IV_MSG_HIGH("%s. orientation=%d", __func__, orientation);
-
-/*
-       enum app_device_orientation_e
-
-       APP_DEVICE_ORIENTATION_0  The device is oriented in natural position
-
-       APP_DEVICE_ORIENTATION_90  The device's left side is at the top
-
-       APP_DEVICE_ORIENTATION_180      The device is upside down
-
-       APP_DEVICE_ORIENTATION_270      The device's right side is to the top
-
-*/
-       appdata_iv *ap = (appdata_iv *)user_data;
-
-       int degree = 0;
-       enum ug_event evt = UG_EVENT_NONE;
-
-       if ( _is_rotation_lock() == true )      // When rotatation lock is set, show application as portrate mode.
-       {
-               orientation = APP_DEVICE_ORIENTATION_0;
-       }
-
-       switch(orientation)
-       {
-       case APP_DEVICE_ORIENTATION_0:
-               degree = 0;
-               evt = UG_EVENT_ROTATE_PORTRAIT;
-               break;
-       case APP_DEVICE_ORIENTATION_90:
-               degree = 90;
-               evt = UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN;
-               break;
-
-       case APP_DEVICE_ORIENTATION_180:
-               degree = 180;
-               evt = UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN;
-               break;
-
-       case APP_DEVICE_ORIENTATION_270:
-               evt = UG_EVENT_ROTATE_LANDSCAPE;
-               degree = 270;
-               break;
-       }
-
-       ug_send_event( evt );
-
-//     IV_MSG_HIGH( "evt = %d, r = %d", evt, r);
-
-       if ( ap->win_main != NULL )
-       {
-               elm_win_rotation_with_resize_set(ap->win_main, degree);
-       }
-}
-
 
 /**
 * @brief The main function
@@ -800,7 +796,9 @@ int main(int argc, char *argv[])
 
        event_callback.low_memory = _low_memory;
        event_callback.low_battery = _low_battery;
-       event_callback.device_orientation = _orient_changed;    /* Rotate is not supported in FMRadio */
+
+//     event_callback.device_orientation = _orient_changed;
+
        event_callback.language_changed = _lang_changed;                /* Currently, Application will terminated when change language */
        event_callback.region_format_changed = NULL;