1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd
*
* Licensed under the Flora License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://floralicense.org/license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "data-provider.h"
#include "app-log.h"
#include "comp-manager.h"
#include "view.h"
#include "battery-data.h"
static void _comp_fill_color(bundle*);
static void _comp_on_editable_update(const watchface_editable_h, int, const watchface_editable_edit_state_e, void*);
static void _comp_draw_complication(watchface_complication_type_e);
static void _comp_on_complication_update(int, const char*, watchface_complication_type_e, const bundle*, void*);
static void _comp_on_ready_for_edit_cb(watchface_editable_container_h, const char*, void*);
static void _comp_init_editable();
static void _comp_init_complication();
static void _comp_battery_status_changed_cb(int level, void* user_data);
static complication_h _comp;
char _colors[COLOR_NUM][10] = {
"AO0401",
"AO0402",
"AO0403",
"AO0404",
"AO0405",
"AO0406",
"AO0407",
"AO0408",
"AO0409",
"AO0410",
"AO0411",
"AO0412",
};
void _comp_battery_status_changed_cb(int level, void* user_data)
{
view_set_battery_status(level, user_data);
}
/*
* @brief draws the complication with the help of edj
* @param Enumeration for Complication Type.
*/
void _comp_draw_complication(watchface_complication_type_e type)
{
int percent;
Evas_Object* watchface_layout;
Edje_Message_Int msg = {0,};
watchface_layout = view_get_watchface_layout();
msg.val = type;
edje_object_message_send(elm_layout_edje_get(watchface_layout), EDJE_MESSAGE_INT, MSG_ID_SET_BATTERY_COMP, &msg);
percent = battery_get_status();
__D("_battery_state_changed_cb %d", percent);
msg.val = percent;
edje_object_message_send(elm_layout_edje_get(watchface_layout), EDJE_MESSAGE_INT, MSG_ID_SET_BATTERY_LEVEL, &msg);
}
/**
* @brief Called when the complication is updated.
* @param[in] complication_id A number that identifies the complication
* @param[in] provider_id The name of the provider
* @param[in] type The type shown in the complication
* @param[in] data The data of the complication provided by the provider
* @param[in] user_data The user data passed from the callback function
*/
void _comp_on_complication_update(int complication_id, const char *provider_id, watchface_complication_type_e type, const bundle *data, void *user_data)
{
__D("%s: Complication Type: %d", __func__, type);
_comp_draw_complication(type);
}
/*
* @brief initializes the complication for watch
*/
void _comp_init_complication()
{
char* current_comp_id = NULL;
int ret;
complication_allowed_list_h allowed_list;
watchface_complication_type_e cur_type;
__D("%s", __func__);
ret = watchface_complication_create(RIGHT_COMP, BATTERY_PROVIDER_ID,
WATCHFACE_COMPLICATION_TYPE_NO_DATA,
WATCHFACE_COMPLICATION_TYPE_NO_DATA|WATCHFACE_COMPLICATION_TYPE_ICON|WATCHFACE_COMPLICATION_TYPE_IMAGE|WATCHFACE_COMPLICATION_TYPE_SHORT_TEXT,
WATCHFACE_COMPLICATION_SHAPE_TYPE_CIRCLE, &_comp);
ret = watchface_complication_allowed_list_create(&allowed_list);
ret = watchface_complication_allowed_list_add(allowed_list, BATTERY_PROVIDER_ID,
WATCHFACE_COMPLICATION_TYPE_NO_DATA|WATCHFACE_COMPLICATION_TYPE_ICON|WATCHFACE_COMPLICATION_TYPE_IMAGE|WATCHFACE_COMPLICATION_TYPE_SHORT_TEXT);
if (ret == WATCHFACE_COMPLICATION_ERROR_EXIST_ID) {
__E("WATCHFACE_COMPLICATION_ERROR_EXIST_ID");
watchface_complication_allowed_list_delete(allowed_list, BATTERY_PROVIDER_ID);
watchface_complication_allowed_list_add(allowed_list, BATTERY_PROVIDER_ID,
WATCHFACE_COMPLICATION_TYPE_NO_DATA|WATCHFACE_COMPLICATION_TYPE_ICON|WATCHFACE_COMPLICATION_TYPE_IMAGE|WATCHFACE_COMPLICATION_TYPE_SHORT_TEXT);
}
ret = watchface_complication_allowed_list_apply(_comp, allowed_list);
watchface_complication_allowed_list_clear(_comp);
ret = watchface_complication_get_current_provider_id(_comp, ¤t_comp_id);
watchface_complication_add_updated_cb(_comp, _comp_on_complication_update, NULL);
if (ret == WATCHFACE_COMPLICATION_ERROR_NONE) {
watchface_complication_get_current_type(_comp, &cur_type);
_comp_draw_complication(cur_type);
free(current_comp_id);
}
battery_add_status_changed_cb(_comp_battery_status_changed_cb, NULL);
}
/*
* @brief fills the selected color in hands
* @param data containing the value for color
*/
void _comp_fill_color(bundle *data)
{
Evas_Object *hands = NULL;
Evas_Object *watchface_layout = NULL;
struct color c;
char *val = NULL;
if (data == NULL) {
__I("NULL data");
return;
}
bundle_get_str(data, "TEST_COLOR", &val);
if (val == NULL) {
__I("NULL color data");
return;
}
c = data_get_color_codes(val);
watchface_layout = view_get_watchface_layout();
if (watchface_layout == NULL)
__E("Failed to get watch face layout");
hands = evas_object_data_get(watchface_layout, DATA_KEY_HANDS_SEC);
evas_object_color_set(hands, c.r, c.g, c.b, c.a);
}
/**
* @brief Called when an editable requests an edit.
* @param handle The editable handle
* The @a handle can be used only in the callback.
* @param selected_idx Index
* @param state Editable state
* @param user_data The user data passed from the callback function
*/
void _comp_on_editable_update(const watchface_editable_h handle,
int selected_idx,
const watchface_editable_edit_state_e state,
void *user_data)
{
bundle *data;
int ed_id;
watchface_editable_get_current_data(handle, &data);
watchface_editable_get_editable_id(handle, &ed_id);
__E("%s: curr state: %d, editable id: %d", __func__, state, ed_id);
if (ed_id == COLOR_EDIT)
_comp_fill_color(data);
}
/**
* @brief Called when the editor is ready to edit.
* @param[in] handle The editable container handle
* @param[in] editor_appid The name of editor
* @param[in] user_data The user data passed from the callback function
*/
void _comp_on_ready_for_edit_cb(watchface_editable_container_h ed_con_h, const char *editor_appid, void *user_data)
{
watchface_editable_geo_h geometry;
complication_candidates_list_h candidates_list = NULL;
bundle *edit_data;
int current_idx = 0;
bundle *selected_data = NULL;
char *current_color = NULL;
watchface_editable_load_current_data(COLOR_EDIT, &selected_data);
bundle_get_str(selected_data, "TEST_COLOR", ¤t_color);
watchface_editable_candidates_list_create(&candidates_list);
for (int i = 0; i < COLOR_NUM; i++) {
edit_data = bundle_create();
bundle_add_str(edit_data, "TEST_COLOR", _colors[i]);
watchface_editable_candidates_list_add(candidates_list, edit_data);
dlog_print(DLOG_ERROR, LOG_TAG, "add element %s", _colors[i]);
if (selected_data != NULL) {
if (strcmp(current_color, _colors[i]) == 0)
current_idx = i;
}
}
watchface_editable_geometry_create(&geometry);
watchface_editable_geometry_set(geometry, 100, 100, 100, 100);
watchface_editable_add_design_element(ed_con_h, COLOR_EDIT, current_idx,
candidates_list, geometry, "Color");
watchface_editable_candidates_list_destroy(candidates_list);
watchface_editable_geometry_set(geometry, 100, 100, 100, 100);
watchface_editable_add_complication(ed_con_h, RIGHT_COMP, _comp, geometry);
watchface_editable_request_edit(ed_con_h, _comp_on_editable_update, user_data);
watchface_editable_geometry_destroy(geometry);
}
/*
* @brief initializes the editables
*/
void _comp_init_editable()
{
bundle * selected_Data = NULL;
watchface_editable_load_current_data(COLOR_EDIT, &selected_Data);
_comp_fill_color(selected_Data);
}
/*
* brief initializes the comp-manager
*/
void comp_init()
{
_comp_init_complication();
_comp_init_editable();
watchface_editable_add_edit_ready_cb(_comp_on_ready_for_edit_cb, NULL);
}
/*
* @brief Removes the callback for editables
*/
void comp_destroy()
{
watchface_editable_remove_edit_ready_cb(_comp_on_ready_for_edit_cb);
}
|