2 * Copyright 2012 Samsung Electronics Co., Ltd
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
8 * http://floralicense.org/license/
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.
19 #include "camera_utils.h"
21 #include "cam_indicator_edc_callback.h"
22 #include "cam_common_edc_callback.h"
24 #include "edc_string.h"
25 #include "edc_image_name.h"
27 #define CHARGING_INTERVAL (0.5)
28 #define SECONDS_IN_HOUR (1*60*60)
29 #define SECONDS_RECORDING_MAX ((99*60*60)+(99*60)+99)
31 static char *storage_image[CAM_STORAGE_NUM] = {
32 INDICATOR_STORAGE_INTERNAL_ICON,
33 INDICATOR_STORAGE_CARD_ICON,
34 INDICATOR_STORAGE_INTERNAL_ICON,
37 #define CAM_BATTERY_LEVEL_MAX 8
38 static char *battery_image[CAM_BATTERY_LEVEL_MAX] = {
39 INDICATOR_BATTERY_LEVEL_00_ICON,
40 INDICATOR_BATTERY_LEVEL_01_ICON,
41 INDICATOR_BATTERY_LEVEL_02_ICON,
42 INDICATOR_BATTERY_LEVEL_03_ICON,
43 INDICATOR_BATTERY_LEVEL_04_ICON,
44 INDICATOR_BATTERY_LEVEL_05_ICON,
45 INDICATOR_BATTERY_FULL_ICON,
46 INDICATOR_BATTERY_CHARGE_ICON,
49 static char *gps_level_image[CAM_LBS_STATE_NUM] = {
50 INDICATOR_GPS_STATE_OFF_ICON,
51 INDICATOR_GPS_STATE_ON_ICON,
52 INDICATOR_GPS_STATE_CONNECT_ANI01_ICON,
53 INDICATOR_GPS_STATE_CONNECT_ANI02_ICON,
54 INDICATOR_GPS_STATE_CONNECT_ANI03_ICON,
57 static char *mute_image = INDICATOR_MUTE_ICON;
59 static Evas_Object *indicator_image_obj_battery = NULL;
60 static Evas_Object *indicator_image_obj_storage = NULL;
61 static Evas_Object *indicator_image_obj_gps_level = NULL;
62 static Evas_Object *indicator_image_obj_mute = NULL;
65 void indicator_update_storage(struct appdata *ad)
69 cam_retm_if(ad == NULL, "appdata is NULL");
70 cam_retm_if(ad->camapp_handle == NULL, "camapp_handle is NULL");
71 cam_retm_if(ad->indicator_edje == NULL, "indicator_edje is NULL");
72 const char *image_file = NULL;
74 vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_CAMERA_INT, &(ad->camapp_handle->storage));
76 if (ad->camapp_handle->storage == CAM_STORAGE_EXTERNAL) {
77 if (!vconf_get_int(VCONFKEY_SYSMAN_MMC_STATUS, &mmc_state)) {
78 if (mmc_state == VCONFKEY_SYSMAN_MMC_REMOVED) {
79 cam_info(LOG_UI, "MMC card is removed");
81 CAM_GVALUE_SET_INT(value, CAM_STORAGE_INTERNAL);
82 cam_handle_value_set(ad, PROP_STORAGE, &value);
87 switch (ad->camapp_handle->storage) {
88 case CAM_STORAGE_INTERNAL:
89 image_file = storage_image[CAM_STORAGE_INTERNAL];
91 case CAM_STORAGE_EXTERNAL:
92 image_file = storage_image[CAM_STORAGE_EXTERNAL];
98 if (!indicator_image_obj_storage) {
99 indicator_image_obj_storage = elm_image_add(ad->indicator_edje);
102 cam_retm_if(indicator_image_obj_storage == NULL,
103 "indicator_image_obj_storage is NULL");
104 elm_image_file_set(indicator_image_obj_storage, CAM_IMAGE_EDJ_NAME, image_file);
106 if (ad->camapp_handle->camera_mode == CAM_CAMCORDER_MODE
107 && ad->is_recording == TRUE)
108 edje_object_part_swallow(_EDJ(ad->indicator_edje), INDI_REC_STORAGE,
109 indicator_image_obj_storage);
111 edje_object_part_swallow(_EDJ(ad->indicator_edje), INDICATOR_STORAGE,
112 indicator_image_obj_storage);
114 ad->remained_count = cam_system_get_still_count_by_resolution(ad);
115 indicator_update_remain_count(ad);
118 void indicator_update_gps_level(struct appdata *ad)
120 debug_fenter(LOG_UI);
121 cam_retm_if(ad == NULL, "appdata is NULL");
122 CamAppData *camapp = ad->camapp_handle;
123 cam_retm_if(camapp == NULL, "camapp is NULL");
124 cam_ret_if(ad->toolbar_hided);
125 cam_retm_if(ad->indicator_edje == NULL, "indicator_edje is NULL");
126 const char *image_file = NULL;
127 /*DEBUG_TRACE("====level : %d", ad->gps_level);*/
128 switch (camapp->gps_level) {
129 case CAM_LBS_STATE_DISABLE:
130 image_file = gps_level_image[CAM_LBS_STATE_DISABLE];
132 case CAM_LBS_STATE_SERVICE_START:
133 image_file = gps_level_image[CAM_LBS_STATE_SERVICE_START];
135 case CAM_LBS_STATE_SERVICE_ENABLE:
136 image_file = gps_level_image[CAM_LBS_STATE_SERVICE_ENABLE];
138 case CAM_LBS_STATE_ACCURANCY_ROUGH:
139 image_file = gps_level_image[CAM_LBS_STATE_ACCURANCY_ROUGH];
141 case CAM_LBS_STATE_ACCURANCY_DETAILED:
142 image_file = gps_level_image[CAM_LBS_STATE_ACCURANCY_DETAILED];
145 image_file = gps_level_image[CAM_LBS_STATE_DISABLE];
147 if (!indicator_image_obj_gps_level) {
148 indicator_image_obj_gps_level =
149 elm_image_add(ad->indicator_edje);
151 cam_retm_if(indicator_image_obj_gps_level == NULL,
152 "indicator_image_obj_gps_level is NULL");
153 elm_image_file_set(indicator_image_obj_gps_level, CAM_IMAGE_EDJ_NAME, image_file);
155 cam_debug(LOG_CAM, "ad->camapp_handle->camera_mode %d", camapp->camera_mode);
156 cam_debug(LOG_CAM, "ad->mm_state %d", ad->mm_state);
158 if (camapp->camera_mode == CAM_CAMCORDER_MODE
159 && ad->is_recording == TRUE) {
160 if (camapp->gps_level == CAM_LBS_STATE_DISABLE) {
161 HIDE_EVAS_OBJECT(indicator_image_obj_gps_level);
162 edje_object_part_unswallow(_EDJ(ad->indicator_edje), indicator_image_obj_gps_level);
165 SHOW_EVAS_OBJECT(indicator_image_obj_gps_level);
166 edje_object_part_swallow(_EDJ(ad->indicator_edje),
168 indicator_image_obj_gps_level);
171 if (camapp->gps_level == CAM_LBS_STATE_DISABLE) {
172 HIDE_EVAS_OBJECT(indicator_image_obj_gps_level);
173 edje_object_part_unswallow(_EDJ(ad->indicator_edje), indicator_image_obj_gps_level);
175 SHOW_EVAS_OBJECT(indicator_image_obj_gps_level);
176 edje_object_part_swallow(_EDJ(ad->indicator_edje),
178 indicator_image_obj_gps_level);
183 void indicator_update_gps(struct appdata *ad)
185 debug_fenter(LOG_UI);
186 cam_retm_if(ad == NULL, "appdata is NULL");
187 cam_retm_if(ad->camapp_handle == NULL, "camapp_handle is NULL");
188 cam_retm_if(ad->indicator_edje == NULL, "indicator_edje is NULL");
189 indicator_update_gps_level(ad);
192 void indicator_update_remain_count(struct appdata *ad)
194 char remain[80] = "";
195 debug_fenter(LOG_UI);
196 cam_retm_if(ad == NULL, "appdata is NULL");
197 cam_retm_if(ad->camapp_handle == NULL, "camapp_handle is NULL");
198 cam_retm_if(ad->indicator_edje == NULL, "indicator_edje is NULL");
200 gint64 remained_count = 0;
201 remained_count = ad->remained_count;
203 if (ad->camapp_handle->camera_mode == CAM_CAMCORDER_MODE && ad->is_recording == TRUE) {
204 snprintf(remain, sizeof(remain), "%s", " ");
206 if (remained_count >= 0 && remained_count < 301) {
207 snprintf(remain, sizeof(remain), "%d", (int)remained_count);
209 snprintf(remain, sizeof(remain), "%d", (int)remained_count);
210 snprintf(remain, sizeof(remain), "%s", " ");
214 DEBUG_TRACE("INDICATOR REMAIN = %s ", remain);
216 edje_object_part_text_set(_EDJ(ad->indicator_edje), INDICATOR_NUM, remain);
219 static Eina_Bool cam_indicator_battery_ani_cb(void *data)
221 struct appdata *ad = data;
222 CamAppData *camapp = NULL;
223 cam_retvm_if(ad == NULL, 0, "appdata is NULL");
224 camapp = ad->camapp_handle;
225 if (camapp == NULL) {
226 ad->battery_animation_timer = NULL;
227 return ECORE_CALLBACK_CANCEL;
231 if (indicator_image_obj_battery) {
232 if (evas_object_visible_get(indicator_image_obj_battery))
233 evas_object_hide(indicator_image_obj_battery);
235 evas_object_show(indicator_image_obj_battery);
238 return ECORE_CALLBACK_RENEW;
241 static void cam_indicator_draw_battery_ani(void *data)
243 struct appdata *ad = data;
244 CamAppData *camapp = NULL;
245 debug_fenter(LOG_UI);
246 cam_retm_if(ad == NULL, "appdata is NULL");
247 camapp = ad->camapp_handle;
248 cam_retm_if(camapp == NULL, "camapp_handle is NULL");
249 if (ad->battery_animation_timer) {
250 cam_debug(LOG_UI, "battery_ani timer already exists! ");
253 ad->battery_animation_timer =
254 ecore_timer_add(CHARGING_INTERVAL, cam_indicator_battery_ani_cb, ad);
257 void indicator_update_battery(struct appdata *ad, int level)
259 cam_retm_if(ad == NULL, "appdata is NULL");
260 cam_retm_if(ad->camapp_handle == NULL, "camapp_handle is NULL");
261 cam_retm_if(ad->indicator_edje == NULL, "indicator_edje is NULL");
262 const char *image_file = NULL;
263 int battery_level = 0;
264 gboolean show_icon = TRUE;
266 if (ad->battery_animation_timer) {
267 ecore_timer_del(ad->battery_animation_timer);
268 ad->battery_animation_timer = NULL;
271 if (ad->camapp_handle->battery_charging) {
274 if (level > 15 && level <= 20) // step2
276 else if (level > 5 && level <= 15) // step1
278 else if (level < 5) {// blinking
280 cam_indicator_draw_battery_ani((void *)ad);
286 cam_debug(LOG_CAM, "level [%d] img_index[%d] show state [%d]", level, battery_level, show_icon);
289 image_file = battery_image[battery_level];
291 if (!indicator_image_obj_battery) {
292 indicator_image_obj_battery = elm_image_add(ad->indicator_edje);
294 cam_retm_if(indicator_image_obj_battery == NULL, "indicator_image_obj_battery is NULL");
295 elm_image_file_set(indicator_image_obj_battery, CAM_IMAGE_EDJ_NAME, image_file);
296 if (ad->camapp_handle->camera_mode == CAM_CAMCORDER_MODE
297 && ad->is_recording == TRUE)
298 edje_object_part_swallow(_EDJ(ad->indicator_edje), INDI_REC_BATTERY, indicator_image_obj_battery);
300 edje_object_part_swallow(_EDJ(ad->indicator_edje), INDICATOR_BATTERY, indicator_image_obj_battery);
302 if (indicator_image_obj_battery)
303 evas_object_hide(indicator_image_obj_battery);
307 void indicator_update_mute_icon(struct appdata *ad)
309 cam_retm_if(ad == NULL, "appdata is NULL");
310 cam_retm_if(ad->camapp_handle == NULL, "camapp_handle is NULL");
311 cam_retm_if(ad->indicator_edje == NULL, "indicator_edje is NULL");
312 const char *image_file = NULL;
314 if ((ad->camapp_handle->camera_mode == CAM_CAMCORDER_MODE)
315 && (ad->camapp_handle->recording_mode == CAM_RECORD_SLOW
316 || ad->camapp_handle->recording_mode == CAM_RECORD_FAST)) {
317 if (ad->is_recording == TRUE) {
318 image_file = mute_image;
320 if (!indicator_image_obj_mute) {
321 indicator_image_obj_mute = elm_image_add(ad->indicator_edje);
324 cam_retm_if(indicator_image_obj_mute == NULL, "indicator_image_obj_mute is NULL");
325 elm_image_file_set(indicator_image_obj_mute, CAM_IMAGE_EDJ_NAME, image_file);
326 edje_object_part_swallow(_EDJ(ad->indicator_edje), INDI_REC_MUTE, indicator_image_obj_mute);
328 DEL_EVAS_OBJECT(indicator_image_obj_mute);
331 DEL_EVAS_OBJECT(indicator_image_obj_mute);
335 void cam_indicator_update(struct appdata *ad)
337 #ifndef CAMERA_MACHINE_I686
338 cam_retm_if(ad == NULL, "appdata is NULL");
339 cam_retm_if(ad->camapp_handle == NULL, "camapp_handle is NULL");
340 indicator_update_battery(ad, ad->camapp_handle->battery_level);
341 DEBUG_TRACE("charging = %d",ad->camapp_handle->battery_charging);
342 indicator_update_storage(ad);
343 indicator_update_gps(ad);
344 indicator_update_mute_icon(ad);
349 void cam_indicator_set_show_state(struct appdata *ad, bool show)
351 cam_retm_if(ad == NULL, "appdata is NULL");
353 if (ad->indicator_edje) {
355 evas_object_show(ad->indicator_edje);
357 evas_object_hide(ad->indicator_edje);
361 int cam_indicator_create(struct appdata *ad)
363 debug_fenter(LOG_UI);
364 cam_retvm_if(ad == NULL, EXIT_FAILURE, "appdata is NULL");
366 if (ad->indicator_edje != NULL) {
367 cam_indicator_update(ad);
368 evas_object_show(ad->indicator_edje);
372 elm_object_part_content_unset(ad->ug_base, "indicator_layout");
374 switch (ad->target_direction) {
375 case CAM_TARGET_DIRECTION_LANDSCAPE:
376 ad->indicator_edje = cam_app_load_edj(ad->ug_base, CAM_INDICATOR_EDJ_NAME, "indicator_landscape");
378 case CAM_TARGET_DIRECTION_LANDSCAPE_INVERSE:
379 ad->indicator_edje = cam_app_load_edj(ad->ug_base, CAM_INDICATOR_EDJ_NAME, "indicator_landscape_inverse");
381 case CAM_TARGET_DIRECTION_PORTRAIT:
382 ad->indicator_edje = cam_app_load_edj(ad->ug_base, CAM_INDICATOR_EDJ_NAME, "indicator_portrait");
384 case CAM_TARGET_DIRECTION_PORTRAIT_INVERSE:
385 ad->indicator_edje = cam_app_load_edj(ad->ug_base, CAM_INDICATOR_EDJ_NAME, "indicator_portrait_inverse");
388 DEBUG_TRACE("note:REACHED UN-ABLE REACHED CODES");
391 cam_retvm_if(ad->indicator_edje == NULL, EXIT_FAILURE, "indicator edje load fail !!!");
392 elm_object_part_content_set(ad->ug_base, "indicator_layout", ad->indicator_edje);
393 cam_indicator_update(ad);
398 int cam_indicator_destory(struct appdata *ad)
400 cam_retv_if(ad == NULL, -1);
402 DEL_EVAS_OBJECT(indicator_image_obj_battery);
403 DEL_EVAS_OBJECT(indicator_image_obj_storage);
404 DEL_EVAS_OBJECT(indicator_image_obj_gps_level);
405 DEL_EVAS_OBJECT(indicator_image_obj_mute);
407 DEL_EVAS_OBJECT(ad->indicator_edje);
411 int cam_indicator_rotate(struct appdata *ad)
413 cam_retv_if(ad == NULL, -1);
414 if (ad->indicator_edje) {
415 /* delete indicator */
416 evas_object_hide(ad->indicator_edje);
417 cam_indicator_destory(ad);
418 cam_indicator_create(ad);
419 if (ad->indicator_edje) {
420 indicator_toggle(ad, FALSE);
421 evas_object_show(ad->indicator_edje);
429 void indicator_toggle(struct appdata *ad, gboolean hide)
431 cam_ret_if(ad == NULL || ad->indicator_edje == NULL);
434 indicator_update_gps(ad);