2 * Copyright (c) 2016 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 "main_view.h"
20 #include "lockscreen.h"
21 #include "util_time.h"
23 #include <Elementary.h>
25 #define EMG_BUTTON_WIDTH 322
26 #define PLMN_LABEL_STYLE_START "<style=far_shadow,bottom><shadow_color=#00000033><font_size=24><align=left><color=#FFFFFF><text_class=ATO007><color_class=ATO007><wrap=none>"
27 #define PLMN_LABEL_STYLE_END "</wrap></color_class></text_class></color></align></font_size></shadow_color></style>"
29 static Evas_Object *_swipe_layout_create(Evas_Object *parent)
31 Evas_Object *swipe_layout = NULL;
32 if (!parent) return NULL;
34 swipe_layout = elm_layout_add(parent);
36 if (!elm_layout_file_set(swipe_layout, util_get_res_file_path(LOCK_EDJE_FILE), "swipe-lock")) {
37 ERR("elm_layout_file_set failed.");
38 evas_object_del(swipe_layout);
42 evas_object_size_hint_weight_set(swipe_layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
43 evas_object_size_hint_align_set(swipe_layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
45 evas_object_show(swipe_layout);
50 void lockscreen_main_view_part_content_set(Evas_Object *view, const char *part, Evas_Object *content)
52 Evas_Object *swipe_layout = elm_object_part_content_get(view, "sw.swipe_layout");
54 FAT("No sw.swipe_layout part");
57 if (!strcmp(PART_EVENTS, part)) {
58 elm_object_signal_emit(swipe_layout, "contextual,events,show", "lockscreen");
60 elm_object_part_content_set(swipe_layout, part, content);
63 Evas_Object *lockscreen_main_view_part_content_unset(Evas_Object *view, const char *part)
65 Evas_Object *swipe_layout = elm_object_part_content_get(view, "sw.swipe_layout");
67 FAT("No sw.swipe_layout part");
70 if (!strcmp(PART_EVENTS, part)) {
71 elm_object_signal_emit(swipe_layout, "contextual,events,hide", "lockscreen");
73 return elm_object_part_content_unset(swipe_layout, part);
76 Evas_Object *lockscreen_main_view_part_content_get(Evas_Object *view, const char *part)
78 Evas_Object *swipe_layout = elm_object_part_content_get(view, "sw.swipe_layout");
80 FAT("No sw.swipe_layout part");
83 return elm_object_part_content_get(swipe_layout, part);
86 static Evas_Event_Flags _swipe_state_end(void *data, void *event_info)
88 evas_object_smart_callback_call(data, SIGNAL_SWIPE_GESTURE_FINISHED, NULL);
89 return EVAS_EVENT_FLAG_NONE;
92 Evas_Object *lockscreen_main_view_create(Evas_Object *win)
94 Evas_Object *layout = elm_layout_add(win);
95 if (!elm_layout_file_set(layout, util_get_res_file_path(LOCK_EDJE_FILE), "lockscreen")) {
96 FAT("Failed to set edje file for main view.");
100 evas_object_show(layout);
101 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
102 evas_object_size_hint_align_set(layout, EVAS_HINT_FILL, EVAS_HINT_FILL);
104 Evas_Object *swipe_layout = _swipe_layout_create(layout);
106 evas_object_del(layout);
109 elm_object_part_content_set(layout, "sw.swipe_layout", swipe_layout);
111 Evas_Object *bg = elm_bg_add(layout);
112 elm_bg_option_set(bg, ELM_BG_OPTION_SCALE);
113 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
114 evas_object_size_hint_align_set(bg, EVAS_HINT_FILL, EVAS_HINT_FILL);
115 elm_object_part_content_set(layout, "sw.bg", bg);
117 Evas_Object *gesture_layer = elm_gesture_layer_add(layout);
118 elm_gesture_layer_hold_events_set(gesture_layer, EINA_TRUE);
119 elm_gesture_layer_attach(gesture_layer, layout);
120 elm_gesture_layer_attach(gesture_layer, swipe_layout);
121 elm_gesture_layer_attach(gesture_layer, bg);
122 elm_gesture_layer_cb_set(gesture_layer, ELM_GESTURE_N_FLICKS, ELM_GESTURE_STATE_END, _swipe_state_end, layout);
123 evas_object_show(gesture_layer);
128 bool lockscreen_main_view_background_set(Evas_Object *view, lockscreen_main_view_background_type type, const char *file)
130 Evas_Object *bg = elm_object_part_content_get(view, "sw.bg");
132 FAT("No sw.bg part");
136 if (!elm_bg_file_set(bg, file, NULL)) {
137 ERR("elm_bg_file_set failed: %s", file);
142 case LOCKSCREEN_BACKGROUND_TYPE_DEFAULT:
143 elm_object_signal_emit(view, "music_off", "lockscreen");
145 case LOCKSCREEN_BACKGROUND_TYPE_ALBUM_ART:
146 elm_object_signal_emit(view, "music_on", "lockscreen");
153 void lockscreen_main_view_battery_status_text_set(Evas_Object *view, const char *battery)
155 Evas_Object *swipe_layout = elm_object_part_content_get(view, "sw.swipe_layout");
157 FAT("No sw.swipe_layout part");
161 elm_object_part_text_set(swipe_layout, "txt.battery", battery);
162 elm_object_signal_emit(swipe_layout, "show,txt,battery", "lockscreen");
164 elm_object_signal_emit(swipe_layout, "hide,txt,battery", "lockscreen");
165 elm_object_part_text_set(swipe_layout, "txt.battery", "");
169 void lockscreen_main_view_sim_status_text_set(Evas_Object *view, const char *text)
171 Evas_Object *swipe_layout = elm_object_part_content_get(view, "sw.swipe_layout");
173 FAT("No sw.swipe_layout part");
176 Evas_Object *label = NULL;
177 char buf[512] = { 0, };
178 char *markup_text = NULL;
179 Evas_Object *tb = NULL;
183 elm_object_signal_emit(swipe_layout, "hide,txt,plmn", "lockscreen");
187 label = elm_label_add(swipe_layout);
188 elm_object_scale_set(label, edje_scale_get() * 0.6);
189 markup_text = elm_entry_utf8_to_markup(text);
190 snprintf(buf, sizeof(buf), "%s%s%s", PLMN_LABEL_STYLE_START, markup_text, PLMN_LABEL_STYLE_END);
193 elm_object_style_set(label, "slide_short");
194 elm_label_wrap_width_set(label, 100);
195 elm_label_ellipsis_set(label, EINA_TRUE);
196 elm_label_slide_duration_set(label, 2);
197 elm_label_slide_mode_set(label, ELM_LABEL_SLIDE_MODE_NONE);
199 Evas_Object *label_edje = elm_layout_edje_get(label);
200 tb = (Evas_Object *)edje_object_part_object_get(label_edje, "elm.text");
202 FAT("elm.text part not found in edje");
205 evas_object_textblock_size_native_get(tb, &tb_w, NULL);
207 if ((tb_w > 0) && (tb_w > ELM_SCALE_SIZE(EMG_BUTTON_WIDTH))) {
208 elm_label_slide_mode_set(label, ELM_LABEL_SLIDE_MODE_AUTO);
211 elm_label_slide_go(label);
212 elm_object_text_set(label, buf);
214 elm_object_part_content_set(swipe_layout, "txt.plmn", label);
215 elm_object_signal_emit(swipe_layout, "show,txt,plmn", "lockscreen");
216 evas_object_show(label);
219 static void _layout_unlocked(void *data, Evas_Object *obj, const char *emission, const char *source)
221 Evas_Object *swipe_layout = elm_object_part_content_get(data, "sw.swipe_layout");
223 FAT("No sw.swipe_layout part");
226 evas_object_smart_callback_call(data, SIGNAL_UNLOCK_ANIMATION_FINISHED, NULL);
227 elm_object_signal_callback_del(swipe_layout, "unlock,anim,end", "swipe-layout", _layout_unlocked);
230 void lockscreen_main_view_unlock(Evas_Object *view)
232 Evas_Object *swipe_layout = elm_object_part_content_get(view, "sw.swipe_layout");
234 FAT("No sw.swipe_layout part");
237 elm_object_signal_callback_add(swipe_layout, "unlock,anim,end", "swipe-layout", _layout_unlocked, view);
238 elm_object_signal_emit(swipe_layout, "unlock,anim,start", "lockscreen");
239 elm_object_signal_emit(view, "bg,hide", "lockscreen");
242 static int _is_korea_locale(const char *locale)
246 if (strstr(locale,"ko_KR")) {
253 void lockscreen_main_view_time_set(Evas_Object *view, const char *locale, const char *timezone, bool use24hformat, time_t time)
255 Evas_Object *swipe_layout = elm_object_part_content_get(view, "sw.swipe_layout");
257 FAT("No sw.swipe_layout part");
260 char buf[PATH_MAX] = {0,};
261 char *str_date, *str_time, *str_meridiem;
263 if (!util_time_formatted_time_get(time, locale, timezone, use24hformat, &str_time, &str_meridiem)) {
264 ERR("util_time_formatted_time_get failed");
267 if (!util_time_formatted_date_get(time, locale, timezone, "MMMMEd", &str_date)) {
268 ERR("util_time_formatted_date_get failed");
275 snprintf(buf, sizeof(buf), "%s", str_time);
277 if (_is_korea_locale(locale)) {
278 snprintf(buf, sizeof(buf), "<%s>%s </>%s", "small_font", str_meridiem, str_time);
280 snprintf(buf, sizeof(buf), "%s<%s> %s</>", str_time, "small_font", str_meridiem);
283 elm_object_part_text_set(swipe_layout, "txt.time", buf);
285 snprintf(buf, sizeof(buf), "<%s>%s</>", "small_font", str_date);
286 elm_object_part_text_set(swipe_layout, "txt.date", buf);
288 snprintf(buf, sizeof(buf), "%s %s", str_time, str_date);
289 elm_object_part_text_set(swipe_layout, "txt.timedate", buf);