a79fe707b3d876177c3d91a66ce768cace71d57a
[apps/native/sample/sample-core-components.git] / rule / wearable / project / src / main.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
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 "$(appName).h"
18 #include "view.h"
19 #include "data.h"
20
21 /*
22  * @brief Hook to take necessary actions before main event loop starts
23  * Initialize UI resources and application's data
24  * If this function returns true, the main loop of application starts
25  * If this function returns false, the application is terminated
26  */
27 static bool app_create(void *user_data)
28 {
29         return true;
30 }
31
32 /*
33  * @brief This callback function is called when another application
34  * sends the launch request to the application
35  */
36 static void app_control(app_control_h app_control, void *user_data)
37 {
38         /* Handle the launch request. */
39 }
40
41 /*
42  * @brief This callback function is called each time
43  * the application is completely obscured by another application
44  * and becomes invisible to the user
45  */
46 static void app_pause(void *user_data)
47 {
48         /* Take necessary actions when application becomes invisible. */
49 }
50
51 /*
52  * @brief This callback function is called each time
53  * the application becomes visible to the user
54  */
55 static void app_resume(void *user_data)
56 {
57         /* Take necessary actions when application becomes visible. */
58 }
59
60 /*
61  * @brief This callback function is called once after the main loop of the application exits
62  */
63 static void app_terminate(void *user_data)
64 {
65         /* Release all resources. */
66 }
67
68 /*
69  * @brief This function will be called when the language is changed
70  */
71 static void ui_app_lang_changed(app_event_info_h event_info, void *user_data)
72 {
73         /*APP_EVENT_LANGUAGE_CHANGED*/
74         char *locale = NULL;
75
76         system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale);
77
78         if (locale != NULL) {
79                 elm_language_set(locale);
80                 free(locale);
81         }
82         return;
83 }
84
85 /*
86  * @brief Main function of the application
87  */
88 int main(int argc, char *argv[])
89 {
90         int ret;
91
92         ui_app_lifecycle_callback_s event_callback = {0, };
93         app_event_handler_h handlers[5] = {NULL, };
94
95         event_callback.create = app_create;
96         event_callback.terminate = app_terminate;
97         event_callback.pause = app_pause;
98         event_callback.resume = app_resume;
99         event_callback.app_control = app_control;
100
101         /*
102          * If you want to handling more events,
103          * Please check the application lifecycle guide
104          */
105         ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, NULL);
106
107         ret = ui_app_main(argc, argv, &event_callback, NULL);
108         if (ret != APP_ERROR_NONE)
109                 dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main() is failed. err = %d", ret);
110
111         return ret;
112 }