2 * Copyright (c) 2009-2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <Elementary.h>
18 #include <efl_extension.h>
20 #include <minicontrol-viewer.h>
23 #include "lockscreen.h"
25 #include "default_lock.h"
28 #include "background_view.h"
30 #include "lock_time.h"
31 #include "sim_state.h"
33 #define INDICATOR_HEIGHT 38
34 #define UNLOCK_DISTANCE 140
36 #define MINICONTROL_BUNDLE_KEY_WIDTH "width"
37 #define MINICONTROL_BUNDLE_KEY_HEIGHT "height"
39 static struct _s_info {
40 Evas_Object *conformant;
42 Evas_Object *swipe_layout;
44 Ecore_Event_Handler *mouse_down_handler;
45 Ecore_Event_Handler *mouse_move_handler;
46 Ecore_Event_Handler *mouse_up_handler;
48 Eina_Bool is_mouse_down;
55 lock_exit_state_e exit_state;
61 .mouse_down_handler = NULL,
62 .mouse_move_handler = NULL,
63 .mouse_up_handler = NULL,
65 .is_mouse_down = EINA_FALSE,
69 .exit_state = LOCK_EXIT_STATE_NORMAL,
72 Evas_Object *lock_default_conformant_get(void)
74 return s_info.conformant;
77 Evas_Object *lock_default_lock_layout_get(void)
82 Evas_Object *lock_default_swipe_layout_get(void)
84 return s_info.swipe_layout;
87 void _default_lock_hw_back_cb(void *data, Evas_Object *obj, void *event_info)
92 static Eina_Bool _default_lock_mouse_down_cb(void *data, int type, void *event)
96 Ecore_Event_Mouse_Button *m = event;
98 int touch_upper_y = 0;
100 retv_if(!m, ECORE_CALLBACK_CANCEL);
101 retv_if(!s_info.swipe_layout, ECORE_CALLBACK_CANCEL);
103 /* (Up to 3 times, 30 seconds) is extended by 10 seconds Control panel area when tap */
104 lockscreen_lcd_off_count_raise();
106 s_info.clicked_x = m->root.x;
107 s_info.clicked_y = m->root.y;
108 _D("clicked x(%d), y(%d)", s_info.clicked_x, s_info.clicked_y);
110 touch_upper_y = INDICATOR_HEIGHT;
111 _D("touch upper y : %d", touch_upper_y);
113 if (m->root.y <= touch_upper_y) {
114 _D("ignore touch event(%d > %d)", m->root.y, touch_upper_y);
115 s_info.is_mouse_down = EINA_FALSE;
117 elm_object_signal_emit(s_info.swipe_layout, "vi_effect_start", "padding.top");
118 s_info.is_mouse_down = EINA_TRUE;
121 return ECORE_CALLBACK_PASS_ON;
124 static Eina_Bool _default_lock_mouse_move_cb(void *data, int type, void *event)
126 Ecore_Event_Mouse_Move *m = event;
127 retv_if(!m, ECORE_CALLBACK_CANCEL);
128 retv_if(m->multi.device != 0, ECORE_CALLBACK_CANCEL);
130 int const dx = m->x - s_info.clicked_x;
131 int const dy = s_info.clicked_y - m->y;
132 int scaled_unlock_distance = _X(UNLOCK_DISTANCE);
133 int distance = sqrt(dx*dx + dy*dy) + _X(20);
135 if (distance >= scaled_unlock_distance) {
136 s_info.exit_state = LOCK_EXIT_STATE_EXIT;
138 s_info.exit_state = LOCK_EXIT_STATE_NORMAL;
141 return ECORE_CALLBACK_DONE;
144 static Eina_Bool _default_lock_mouse_up_cb(void *data, int type, void *event)
148 Ecore_Event_Mouse_Button *m = event;
150 retv_if(!m, ECORE_CALLBACK_CANCEL);
151 retv_if(m->multi.device != 0, ECORE_CALLBACK_CANCEL);
152 retv_if(!s_info.layout, ECORE_CALLBACK_CANCEL);
153 retv_if(!s_info.swipe_layout, ECORE_CALLBACK_CANCEL);
156 if (s_info.is_mouse_down == EINA_FALSE) {
157 _I("ignore touch event");
158 return ECORE_CALLBACK_CANCEL;
161 s_info.is_mouse_down = EINA_FALSE;
163 switch(s_info.exit_state) {
164 case LOCK_EXIT_STATE_NORMAL :
167 case LOCK_EXIT_STATE_EXIT :
168 _D("exit lockscreen");
170 elm_object_signal_emit(s_info.swipe_layout, "vi_effect", "padding.top");
171 elm_object_signal_emit(s_info.layout, "vi_effect", "vi_clipper");
172 return ECORE_CALLBACK_CANCEL;
174 _E("type error : %d", s_info.exit_state);
178 s_info.exit_state = LOCK_EXIT_STATE_NORMAL;
180 elm_object_signal_emit(s_info.swipe_layout, "vi_effect_stop", "padding.top");
181 elm_object_signal_emit(s_info.layout, "vi_effect_stop", "vi_clipper");
182 elm_object_signal_emit(s_info.swipe_layout, "show,txt,plmn", "txt.plmn");
184 return ECORE_CALLBACK_PASS_ON;
187 static void _vi_effect_end_cb(void *data, Evas_Object *obj, const char *emission, const char *source)
194 static lock_error_e _unlock_panel_create(void)
196 retv_if(!s_info.swipe_layout, LOCK_ERROR_FAIL);
198 s_info.mouse_down_handler = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, _default_lock_mouse_down_cb, NULL);
199 if (!s_info.mouse_down_handler) {
200 _E("Failed to add mouse down handler");
203 s_info.mouse_move_handler = ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE, _default_lock_mouse_move_cb, NULL);
204 if (!s_info.mouse_move_handler) {
205 _E("Failed to add mouse move handler");
208 s_info.mouse_up_handler = ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP, _default_lock_mouse_up_cb, NULL);
209 if (!s_info.mouse_up_handler) {
210 _E("Failed to add mouse up handler");
213 elm_object_signal_callback_add(s_info.swipe_layout, "vi_effect_end", "vi_clipper", _vi_effect_end_cb, NULL);
215 return LOCK_ERROR_OK;
218 static Evas_Object *_swipe_layout_create(Evas_Object *parent)
220 Evas_Object *swipe_layout = NULL;
222 retv_if(!parent, NULL);
224 swipe_layout = elm_layout_add(parent);
225 retv_if(!swipe_layout, NULL);
227 if (!elm_layout_file_set(swipe_layout, LOCK_EDJE_FILE, "swipe-lock")) {
228 _E("Failed to set edje file for swipe lock");
232 evas_object_size_hint_weight_set(swipe_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
233 evas_object_size_hint_align_set(swipe_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
235 evas_object_show(swipe_layout);
236 s_info.swipe_layout = swipe_layout;
238 /* initialize time & date information */
241 /* initialize battery information */
242 if (LOCK_ERROR_OK != lock_battery_init()) {
243 _E("Failed to initialize battery information");
246 /* initialize PLMN-SPN information */
247 if (LOCK_ERROR_OK != lock_sim_state_init()) {
248 _E("Failed to initialize sim state");
254 _E("Failed to create swipe layout");
257 evas_object_del(swipe_layout);
264 static Evas_Object *_layout_create(void)
266 Evas_Object *layout = NULL;
267 Evas_Object *swipe_layout = NULL;
268 Evas_Object *win = NULL;
270 win = lock_window_win_get();
273 layout = elm_layout_add(win);
274 retv_if(!layout, NULL);
276 evas_object_show(layout);
278 if (!elm_layout_file_set(layout, LOCK_EDJE_FILE, "lockscreen")) {
279 _E("Failed to set edje file");
283 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
284 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
286 swipe_layout = _swipe_layout_create(layout);
288 _E("Failed to create swipe layout");
292 elm_object_part_content_set(layout, "sw.swipe_layout", swipe_layout);
293 if (!elm_object_part_content_get(layout, "sw.swipe_layout")) {
294 _E("Failed to set swipe layout");
298 elm_win_resize_object_add(win, layout);
303 _E("Failed to create layout");
306 evas_object_del(layout);
311 evas_object_del(swipe_layout);
318 static Evas_Object *_comformant_create(void)
320 Evas_Object *conformant = NULL;
321 Evas_Object *win = NULL;
323 win = lock_window_win_get();
326 conformant = elm_conformant_add(win);
327 retv_if(!conformant, NULL);
329 evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
330 elm_win_resize_object_add(win, conformant);
332 elm_win_indicator_mode_set(win, ELM_WIN_INDICATOR_SHOW);
333 elm_object_signal_emit(conformant, "elm,state,indicator,overlap", "elm");
335 evas_object_show(conformant);
340 lock_error_e lock_default_lock_init(void)
342 Evas_Object *conformant = NULL;
343 Evas_Object *layout = NULL;
344 Evas_Object *bg = NULL;
348 layout = _layout_create();
349 goto_if(!layout, ERROR);
351 s_info.layout = layout;
353 conformant = _comformant_create();
354 goto_if(!conformant, ERROR);
355 s_info.conformant = conformant;
357 eext_object_event_callback_add(layout, EEXT_CALLBACK_BACK, _default_lock_hw_back_cb, NULL);
359 bg = lock_background_view_bg_get();
361 _E("Failed to get BG");
363 elm_object_part_content_set(layout, "sw.bg", bg);
366 ret = _unlock_panel_create();
367 goto_if(LOCK_ERROR_OK != ret, ERROR);
369 return LOCK_ERROR_OK;
372 _E("Failed to initialize default lock");
375 evas_object_del(conformant);
380 evas_object_del(layout);
384 return LOCK_ERROR_FAIL;
387 void lock_default_lock_fini(void)
389 /* delete network status */
390 lock_sim_state_deinit();
392 /* delete batteyr information */
395 /* delete data&time information */
398 /* delete wallpaper */
399 lock_background_view_bg_del();
401 if (s_info.mouse_down_handler) {
402 ecore_event_handler_del(s_info.mouse_down_handler);
403 s_info.mouse_down_handler = NULL;
406 if (s_info.mouse_move_handler) {
407 ecore_event_handler_del(s_info.mouse_move_handler);
408 s_info.mouse_move_handler = NULL;
411 if (s_info.mouse_up_handler) {
412 ecore_event_handler_del(s_info.mouse_up_handler);
413 s_info.mouse_up_handler = NULL;
416 if (s_info.swipe_layout) {
417 evas_object_del(s_info.swipe_layout);
418 s_info.swipe_layout = NULL;
421 if (s_info.conformant) {
422 evas_object_del(s_info.conformant);
423 s_info.conformant = NULL;
427 eext_object_event_callback_del(s_info.layout, EEXT_CALLBACK_BACK, _default_lock_hw_back_cb);
428 evas_object_del(s_info.layout);
429 s_info.layout = NULL;