[Other]Tizen 2.0 branch
[apps/core/preloaded/lockscreen.git] / src / bg.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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
7  *
8  *  http://www.tizenopensource.org/license
9  *
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.
15  */
16
17 #include <dlog.h>
18 #include <vconf.h>
19 #include <vconf-keys.h>
20
21 #include "lockscreen.h"
22 #include "util.h"
23 #include "simple-password.h"
24 #include "complex-password.h"
25
26 static double _get_move(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2)
27 {
28         return ((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
29 }
30
31 static void _flick_event_process(struct appdata *ad)
32 {
33         int status = 0;
34         int locktype = 0;
35
36         vconf_get_int(VCONFKEY_SETAPPL_SCREEN_LOCK_TYPE_INT, &locktype);
37         if(locktype == SETTING_SCREEN_LOCK_TYPE_SIMPLE_PASSWORD){
38                 simple_password_layout_create(ad);
39         } else if(locktype == SETTING_SCREEN_LOCK_TYPE_PASSWORD){
40                 complex_password_layout_create(ad);
41         }
42 }
43
44 void _mouse_down_cb_s(void *data, Evas * evas, Evas_Object * obj, void *event_info)
45 {
46         LOGD("[ == %s == ]", __func__);
47         struct appdata *ad = data;
48         if (ad == NULL)
49                 return;
50
51         evas_pointer_output_xy_get(evas_object_evas_get(obj), &ad->posx[POS_DOWN], &ad->posy[POS_DOWN]);
52         if(ad->posy[POS_DOWN] < FLICK_LINE) {
53                 return;
54         }else {
55                 ad->bFlick = 1;
56                 ad->posx[POS_REC] = ad->posx[POS_DOWN];
57                 ad->posy[POS_REC] = ad->posy[POS_DOWN];
58         }
59 }
60
61 void _mouse_move_cb_s(void *data, Evas * evas, Evas_Object * obj, void *event_info)
62 {
63         struct appdata *ad = data;
64         if (ad == NULL)
65                 return;
66
67         if(ad->bFlick == 1) {
68                 evas_pointer_output_xy_get(evas_object_evas_get(obj), &ad->posx[POS_MOVE], &ad->posy[POS_MOVE]);
69                 if(ad->posy[POS_MOVE] < ad->posy[POS_REC]) {
70                         double d = _get_move(ad->posx[POS_DOWN], ad->posy[POS_DOWN], ad->posx[POS_MOVE], ad->posy[POS_MOVE]);
71                         if(d > (_X(84100)*1.3)) {
72                                 ad->bFlick = 0;
73                                 LOCK_SCREEN_TRACE_DBG("====move info up====");
74                                 _flick_event_process(ad);
75                         }
76                         ad->posx[POS_REC] = ad->posx[POS_MOVE];
77                         ad->posy[POS_REC] = ad->posy[POS_MOVE];
78                 }
79         }
80 }
81
82 void _mouse_up_cb_s(void *data, Evas * evas, Evas_Object * obj, void *event_info)
83 {
84         struct appdata *ad = data;
85         if (ad == NULL)
86                 return;
87
88         if(ad->bFlick == 1) {
89                 ad->bFlick = 0;
90                 evas_pointer_output_xy_get(evas_object_evas_get(obj), &ad->posx[POS_UP], &ad->posy[POS_UP]);
91                 if(ad->posy[POS_UP] < ad->posy[POS_REC]) {
92                         double d = _get_move(ad->posx[POS_DOWN], ad->posy[POS_DOWN], ad->posx[POS_UP], ad->posy[POS_UP]);
93                         if(d > (_X(84100)*1.3)) {
94                                 LOCK_SCREEN_TRACE_DBG("====move info up====");
95                                 _flick_event_process(ad);
96                         }
97                 }
98         }
99 }
100
101 void _slider_down_cb(void *data, Evas * evas, Evas_Object * obj, void *event_info)
102 {
103         Evas_Event_Mouse_Down *ev = event_info;
104         struct appdata *ad = (struct appdata *) data;
105
106         if (ad == NULL) {
107                 LOCK_SCREEN_TRACE_DBG("appdata is NULL");
108                 return;
109         }
110
111         if (ev == NULL) {
112                 LOCK_SCREEN_TRACE_DBG("event_info is NULL");
113                 return;
114         }
115
116         if (ad->slider_rel1.x <= ev->canvas.x && ad->slider_rel1.y <= ev->canvas.y
117                         && (ad->slider_rel1.x + ad->slider_rel1.w) >= ev->canvas.x
118                         && (ad->slider_rel1.y + ad->slider_rel1.h) >= ev->canvas.y) {
119                 ad->bDrag= 1;
120
121                 edje_object_signal_emit(_EDJ(ad->slider), "press",
122                                 "lock.image.l");
123                 edje_object_signal_emit(_EDJ(ad->slider), "press02",
124                                 "lock.image.r");
125         } else {
126                 LOCK_SCREEN_TRACE_DBG("sliding is canceled");
127                 ad->bDrag= 0;
128         }
129 }
130
131 void _slider_move_cb(void *data, Evas * evas, Evas_Object * obj, void *event_info)
132 {
133         Evas_Event_Mouse_Move *ev = event_info;
134         struct appdata *ad = (struct appdata *) data;
135         int step_width = 0;
136         int step_number = 0;
137         int alpha = 0;
138
139         if (ad == NULL) {
140                 LOCK_SCREEN_TRACE_DBG("appdata is NULL");
141                 return;
142         }
143
144         if (ev == NULL) {
145                 LOCK_SCREEN_TRACE_DBG("event_info is NULL");
146                 return;
147         }
148
149         if (ad->bDrag == 0)
150         {
151                 return;
152         }
153
154         if (ad->slider_rel1.x <= ev->cur.canvas.x
155                         && ad->slider_rel1.y <= ev->cur.canvas.y
156                         && (ad->slider_rel2.x + ad->slider_rel2.w) >= ev->cur.canvas.x
157                         && (ad->slider_rel2.y + ad->slider_rel2.h) >= ev->cur.canvas.y) {
158                 ad->bDrag = 1;
159
160                 step_width = (ad->slider_rel2.x + ad->slider_rel2.w - ad->slider_rel1.x)
161                                 / 14;
162                 step_number = (ev->cur.canvas.x - ad->slider_rel1.x) / step_width;
163
164                 alpha = 255 - (2.55 * step_number * 3);
165
166                 if (step_number < 1) {
167                         edje_object_signal_emit(_EDJ(ad->slider), "press02",
168                                         "lock.image.r");
169                 } else if (step_number < 2) {
170                         edje_object_signal_emit(_EDJ(ad->slider), "press03",
171                                         "lock.image.r");
172                 } else if (step_number < 3) {
173                         edje_object_signal_emit(_EDJ(ad->slider), "press04",
174                                         "lock.image.r");
175                 } else if (step_number < 4) {
176                         edje_object_signal_emit(_EDJ(ad->slider), "press05",
177                                         "lock.image.r");
178                 } else if (step_number < 5) {
179                         edje_object_signal_emit(_EDJ(ad->slider), "press06",
180                                         "lock.image.r");
181                 } else if (step_number < 6) {
182                         edje_object_signal_emit(_EDJ(ad->slider), "press07",
183                                         "lock.image.r");
184                 } else if (step_number < 7) {
185                         edje_object_signal_emit(_EDJ(ad->slider), "press08",
186                                         "lock.image.r");
187                 } else if (step_number < 8) {
188                         edje_object_signal_emit(_EDJ(ad->slider), "press09",
189                                         "lock.image.r");
190                 } else if (step_number < 9) {
191                         edje_object_signal_emit(_EDJ(ad->slider), "press10",
192                                         "lock.image.r");
193                 } else if (step_number < 10) {
194                         edje_object_signal_emit(_EDJ(ad->slider), "press11",
195                                         "lock.image.r");
196                 } else if (step_number < 11) {
197                         edje_object_signal_emit(_EDJ(ad->slider), "press12",
198                                         "lock.image.r");
199                 } else if (step_number < 12) {
200                         edje_object_signal_emit(_EDJ(ad->slider), "press13",
201                                         "lock.image.r");
202                 } else if (step_number < 13) {
203                         edje_object_signal_emit(_EDJ(ad->slider), "press14",
204                                         "lock.image.r");
205                 } else {
206                         edje_object_signal_emit(_EDJ(ad->slider), "press15",
207                                         "lock.image.r");
208                 }
209                 evas_object_color_set(ad->ly_main, alpha, alpha, alpha, alpha);
210         } else {
211                 LOCK_SCREEN_TRACE_DBG("sliding is canceled");
212                 ad->bDrag = 0;
213
214                 evas_object_color_set(ad->ly_main, 255, 255, 255, 255);
215
216                 edje_object_signal_emit(_EDJ(ad->slider), "release",
217                                 "lock.image.l");
218                 edje_object_signal_emit(_EDJ(ad->slider), "release",
219                                 "lock.image.r");
220         }
221
222 }
223
224 void _slider_up_cb(void *data, Evas * evas, Evas_Object * obj, void *event_info)
225 {
226         Evas_Event_Mouse_Up *ev = event_info;
227         struct appdata *ad = (struct appdata *) data;
228
229         if (ad == NULL) {
230                 LOCK_SCREEN_TRACE_DBG("appdata is NULL");
231                 return;
232         }
233
234         if (ev == NULL) {
235                 LOCK_SCREEN_TRACE_DBG("event_info is NULL");
236                 return;
237         }
238
239         if (ad->bDrag == 1 && ad->slider_rel2.x <= ev->canvas.x
240                         && ad->slider_rel2.y <= ev->canvas.y
241                         && (ad->slider_rel2.x + ad->slider_rel2.w) >= ev->canvas.x
242                         && (ad->slider_rel2.y + ad->slider_rel2.h) >= ev->canvas.y) {
243                 ad->bDrag = 1;
244         } else {
245                 LOCK_SCREEN_TRACE_DBG("sliding is canceled");
246                 ad->bDrag= 0;
247         }
248
249         edje_object_signal_emit(_EDJ(ad->slider), "release", "lock.image.l");
250         edje_object_signal_emit(_EDJ(ad->slider), "release", "lock.image.r");
251
252         if (ad->bDrag == 1) {
253                 LOCK_SCREEN_TRACE_DBG("unlock the lock-screen");
254                 app_efl_exit();
255         }
256
257         evas_object_color_set(ad->ly_main, 255, 255, 255, 255);
258
259         ad->bDrag = 0;
260 }