tizen 2.3.1 release
[apps/home/settings.git] / setting-display / src / setting-display-smart-screen-smart-rotation.c
1 /*
2  * setting
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 #include <setting-display-smart-screen-smart-rotation.h>
22
23
24 static int setting_display_smart_screen_smart_rotation_create(void *cb);
25 static int setting_display_smart_screen_smart_rotation_destroy(void *cb);
26 static int setting_display_smart_screen_smart_rotation_update(void *cb);
27 static int setting_display_smart_screen_smart_rotation_cleanup(void *cb);
28
29 setting_view setting_view_display_smart_screen_smart_rotation = {
30         .create = setting_display_smart_screen_smart_rotation_create,
31         .destroy = setting_display_smart_screen_smart_rotation_destroy,
32         .update = setting_display_smart_screen_smart_rotation_update,
33         .cleanup = setting_display_smart_screen_smart_rotation_cleanup,
34 };
35
36 static int setting_display_smart_screen_smart_rotation_create(void *cb)
37 {
38         SETTING_TRACE_BEGIN;
39         /* error check */
40         setting_retvm_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER, "cb is NULL");
41         SettingDisplayUG *ad = (SettingDisplayUG *) cb;
42
43         Elm_Object_Item *nav_item = NULL;
44         Evas_Object *sub_layout = elm_layout_add(ad->win_main_layout);
45         elm_layout_file_set(sub_layout, SETTING_THEME_EDJ_NAME, "smart_tryit");
46         /*top guide*/
47         edje_object_part_text_set(_EDJ(sub_layout), "top_popup.text", _(KeyStr_Smart_Top_Popup_Text));
48         Evas_Object *smart_icon = setting_create_image(sub_layout, IMG_SMART_SCREEN_ICON);
49         elm_object_part_content_set(sub_layout, "smart_icon", smart_icon);
50         /*elm_object_signal_emit(sub_layout,"elm,state,top,show","elm"); */
51         /*center guide*/
52         edje_object_part_text_set(_EDJ(sub_layout), "center_popup.text", _(KeyStr_Smart_Rotation_Center_Popup_Text));
53         ad->smart_rotation_sublayout = sub_layout;
54         Evas_Object *scroller = elm_scroller_add(sub_layout);
55         elm_scroller_bounce_set(scroller, EINA_TRUE, EINA_TRUE);
56
57         elm_scroller_policy_set(scroller, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_OFF);
58         evas_object_show(scroller);
59         elm_object_part_content_set(ad->smart_rotation_sublayout, "bg_swallow", scroller);
60
61
62         ad->smart_rotation_image = evas_object_image_add(ad->evas);
63         int h = 0;
64         int w = 0;
65         app_device_orientation_e m = elm_win_rotation_get(ad->win_get);
66         if (APP_DEVICE_ORIENTATION_90 == m || APP_DEVICE_ORIENTATION_270 == m) {
67                 /*ecore_x_window_size_get(ecore_x_window_root_first_get(), &h, &w); */
68                 h = SAMRT_SCREEN_TRY_IT_IAMGE_LANDSCAPE_H;
69                 w = SAMRT_SCREEN_TRY_IT_IAMGE_LANDSCAPE_W;
70
71                 evas_object_image_file_set(ad->smart_rotation_image, SMART_SCREEN_TRY_IT_IMAGE_L, NULL);
72
73         } else {
74                 /*ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h); */
75                 h = SAMRT_SCREEN_TRY_IT_IAMGE_PORTRAIT_H;
76                 w = SAMRT_SCREEN_TRY_IT_IAMGE_PORTRAIT_W;
77                 evas_object_image_file_set(ad->smart_rotation_image, SMART_SCREEN_TRY_IT_IMAGE_P, NULL);
78         }
79
80
81         /*evas_object_image_load_size_set(palm_start_image, ad->original_img_w, h); */
82         evas_object_size_hint_weight_set(ad->smart_rotation_image, 0.0, EVAS_HINT_EXPAND);
83         evas_object_image_fill_set(ad->smart_rotation_image, 0, 0, w, h);
84         evas_object_image_border_set(ad->smart_rotation_image, 16, 16, 16, 16); /*for round corner */
85         evas_object_image_filled_set(ad->smart_rotation_image, 1); /*to full fill */
86         evas_object_size_hint_min_set(ad->smart_rotation_image, ELM_SCALE_SIZE(w), ELM_SCALE_SIZE(h));
87         evas_object_size_hint_max_set(ad->smart_rotation_image, w, h);
88
89         elm_object_part_content_set(ad->smart_rotation_sublayout, "bg_swallow", scroller);
90         elm_object_content_set(scroller, ad->smart_rotation_image);
91
92         /*setting_resize_object(ad->smart_rotation_image, w, h); */
93         elm_scroller_region_bring_in(scroller, 0, 0, 0, 0);
94         setting_disable_evas_object(scroller);
95
96         if (ad->view_to_load == &setting_view_display_smart_screen_smart_rotation) {
97                 ad->ly_main = setting_create_layout_navi_bar(ad->win_main_layout, ad->win_get,
98                                                              NULL,
99                                                              "IDS_COM_BODY_BACK",
100                                                              NULL,
101                                                              NULL,
102                                                              __setting_display_smart_screen_smart_rotation_click_softkey_back_cb,
103                                                              NULL, NULL,
104                                                              ad, sub_layout, &ad->navi_bar, NULL);
105                 nav_item = elm_naviframe_top_item_get(ad->navi_bar);
106         } else {
107                 nav_item = setting_push_layout_navi_bar(NULL,
108                                                         NULL,
109                                                         NULL,
110                                                         NULL,
111                                                         __setting_display_smart_screen_smart_rotation_click_softkey_back_cb,
112                                                         NULL,
113                                                         NULL, ad, sub_layout, ad->navi_bar, NULL);
114         }
115         elm_naviframe_item_pop_cb_set(nav_item, (Elm_Naviframe_Item_Pop_Cb)__setting_display_smart_screen_smart_rotation_click_softkey_back_cb, ad);
116         elm_naviframe_item_title_enabled_set(nav_item, EINA_FALSE, EINA_FALSE);
117
118         /*if smart rotation is on, show guide popup*/
119         /*if smart rotation is off, show guide popuup after user click enable*/
120         int smart_rotation_status = 0;
121         vconf_get_bool(VCONFKEY_SETAPPL_SMARTSCREEN_SMART_ROTATION, &smart_rotation_status);
122         if (smart_rotation_status && !safeStrCmp(ad->uri, URI_SMART_ROTATION)) {
123                 if (ad->smart_rotation_sublayout) {
124                         elm_object_signal_emit(ad->smart_rotation_sublayout, "elm,state,top,show", "elm");
125                         ad->timer_show_guide = ecore_timer_add(4, (Ecore_Task_Cb)__show_smartrotation_guide_popup, ad);
126                 } else {
127                         SETTING_TRACE("layout is null");
128                 }
129         }
130
131
132         setting_view_display_smart_screen_smart_rotation.is_create = 1;
133         return SETTING_RETURN_SUCCESS;
134 }
135
136
137 static int setting_display_smart_screen_smart_rotation_destroy(void *cb)
138 {
139         SETTING_TRACE_BEGIN;
140         /* error check */
141         setting_retvm_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER, "cb is NULL");
142         retv_if(!(setting_view_display_smart_screen_smart_rotation.is_create), SETTING_GENERAL_ERR_NULL_DATA_PARAMETER);
143         SettingDisplayUG *ad = (SettingDisplayUG *) cb;
144         if (ad->timer_show_guide) {
145                 ecore_timer_del(ad->timer_show_guide);
146                 ad->timer_show_guide = NULL;
147         }
148         if (&setting_view_display_smart_screen_smart_rotation == ad->view_to_load) {
149                 if (ad->ly_main) {
150                         evas_object_del(ad->ly_main);
151                         ad->ly_main = NULL;
152                 }
153         } else {
154                 elm_naviframe_item_pop(ad->navi_bar);
155         }
156         setting_view_display_smart_screen_smart_rotation.is_create = 0;
157
158         return SETTING_RETURN_SUCCESS;
159 }
160
161 static int setting_display_smart_screen_smart_rotation_update(void *cb)
162 {
163         SETTING_TRACE_BEGIN;
164         /* error check */
165         setting_retvm_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER, "cb is NULL");
166
167         return SETTING_RETURN_SUCCESS;
168 }
169
170 static int setting_display_smart_screen_smart_rotation_cleanup(void *cb)
171 {
172         SETTING_TRACE_BEGIN;
173         setting_retvm_if(cb == NULL, SETTING_GENERAL_ERR_NULL_DATA_PARAMETER, "cb is NULL");
174
175         SettingDisplayUG *ad = (SettingDisplayUG *) cb;
176
177         setting_display_smart_screen_smart_rotation_destroy(ad);
178
179         return SETTING_RETURN_SUCCESS;
180 }
181
182 /* ***************************************************
183  *
184  *general func
185  *
186  ***************************************************/
187
188 static void __setting_display_smart_screen_smart_rotation_click_softkey_back_cb(void *data, Evas_Object *obj, void *event_info)
189 {
190         SETTING_TRACE_BEGIN;
191         /* error check */
192         setting_retm_if(data == NULL,
193                         "[Setting > Display] Data parameter is NULL");
194
195         SettingDisplayUG *ad = (SettingDisplayUG *) data;
196         if (&setting_view_display_smart_screen_smart_rotation == ad->view_to_load) {
197                 /* Send destroy request */
198                 ug_destroy_me(ad->ug);
199                 return;
200         } else {
201                 setting_view_cleanup(&setting_view_display_smart_screen_smart_rotation, ad);
202         }
203 }